Page 1 of 1

Little help with script for CO2

Posted: Sunday 18 August 2019 20:53
by domogijs
Hi

I am no progammer and can use a little help with this script :)

The idea is that my ikea lamp turns red when co2 is to high.

I have made this script

Code: Select all

return {
    on = { devices = { "CO2" }},
    
    execute = function(domoticz, device)
        Ikea = domoticz.devices(792)
        
        if  (domoticz.devices('CO2').CO2 > 800) then
            
            Ikea.setColorBrightness(100, 100, 5)
        else
            Ikea.switchOff()
        end
    end
}
But i get errors in the log.

Code: Select all


2019-08-18 20:42:35.413 (Netatmo) Air Quality (CO2)
2019-08-18 20:42:35.419 (Netatmo) General/Sound Level (DB)
2019-08-18 20:42:35.773 Status: dzVents: Info: Handling events for: "CO2", value: "617"
2019-08-18 20:42:35.773 Status: dzVents: Info: ------ Start internal script: CO2: Device: "CO2 (Netatmo)", Index: 854
2019-08-18 20:42:35.775 Status: dzVents: Info: ------ Finished CO2
2019-08-18 20:42:35.775 Error: dzVents: Error: (2.4.28) An error occurred when calling event handler CO2
2019-08-18 20:42:35.775 Error: dzVents: Error: (2.4.28) /home/pi/domoticz/scripts/dzVents/generated_scripts/CO2.lua:8: attempt to compare number with nil

What is wrong in the script?

Greets Gijs

Re: Little help with script for CO2  [Solved]

Posted: Sunday 18 August 2019 21:11
by elmortero
Hi,

Try with (domoticz.devices('CO2').co2 > 800) instead of (domoticz.devices('CO2').CO2 > 800)
It is case sensitive and .co2 should be lower case

Re: Little help with script for CO2

Posted: Sunday 18 August 2019 22:44
by domogijs
yes! works thanks for taking the effort pointing this out.

Greets Gijs