Simple compare temp to a switch on/off action

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Backbone
Posts: 51
Joined: Thursday 22 October 2015 21:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: The Netherlands
Contact:

Simple compare temp to a switch on/off action

Post by Backbone »

Good day,

I am stuck on the basics of DZvents.
I can manually switch 'tasmota_switch_kelder' On and Off

Ground_temperature is taken from the Buienradar value which comes as a single value on its own.
2021-06-21 07:46:17.536 buienradar: Temp (ground_temperature)

However the below code gives this error in the log.
Where line 9 error = if (device.name == 'ground_temperature' and device.temperature <17) then

2021-06-21 07:43:00.631 Error: dzVents: Error: (3.1.7) An error occurred when calling event handler Kelder
2021-06-21 07:43:00.631 Error: dzVents: Error: (3.1.7) ...pi/domoticz/scripts/dzVents/generated_scripts/Kelder.lua:9: attempt to index a nil value (global 'device')

Code: Select all

return
{
    on =
    {
        timer = {'every minute'}
    },
    execute = function(dz, item)
        if (device.name == 'ground_temperature' and device.temperature <17) then
            dz.devices('tasmota_switch_kelder').switchOn()
            else
            dz.devices('tasmota_switch_kelder').switchOff()
        end
    end
}
Where is my hickup?

Paco
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Simple compare temp to a switch on/off action

Post by EddyG »

Change

Code: Select all

        if (device.name == 'ground_temperature' and device.temperature <17) then
in

Code: Select all

        if (dz.devices("ground_temperature").temperature <17) then
Backbone
Posts: 51
Joined: Thursday 22 October 2015 21:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: The Netherlands
Contact:

Re: Simple compare temp to a switch on/off action

Post by Backbone »

Thanks EddyG,

It works now.

I took a sample code from the wiki and reworked it to what I had.

Paco
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest