Page 1 of 1

Simple compare temp to a switch on/off action

Posted: Monday 21 June 2021 7:49
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

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

Posted: Monday 21 June 2021 9:15
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

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

Posted: Monday 21 June 2021 10:51
by Backbone
Thanks EddyG,

It works now.

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

Paco