Page 1 of 1

Question regarding Value of Ikea Air quality Sensor

Posted: Monday 14 February 2022 12:12
by mastadook
Hi All,

I made 2 Ikea Air Quality Sensors to Custom sensors to send the Data via mqtt to my Domoticz.
This is working since Weeks now.
What I try to do now, is to send a Mail when the Value is too high
and add the Value Data to the Mail.
For Values like Temperature, this is working with : bla bla bla ..temp.. °C bla bla bla
But I can´t fins equivalent for my Sensor, the Senso looks like this in Domoticz:
sensor1.png
sensor1.png (6.96 KiB) Viewed 890 times
I tried with ..value.. or ..sensordatavalues[1].value.. or ..sensordatavalues[1]..
Nothing works, always Nil Value in Data.

Here is the Script:

Code: Select all

return {
	active = true,
	
	 --on = { devices = { 'Feinstaubsensor EG'}},
     on = {timer = {"every 1 Minutes between 00:10 and 23:50"}},

	execute = function(domoticz, device, email)
	    
if domoticz.devices('Feinstaubsensor EG').sensorValue >= 80 --110 --86
then domoticz.devices('Feinstaubbelastung EG').updateAlertSensor(domoticz.ALERTLEVEL_RED, 'stark erhöht, FFP2 oder FFP3 Maske anziehen')
     domoticz.email('Feinstaubbelastung EG', 'Achtung stark erhöhte Feinstaubwerte, es könnte auch ein Feuer sein' ..sensordatavalues[1].value.. ' Partikel Dichte', '[email protected]')

elseif domoticz.devices('Feinstaubsensor EG').sensorValue >= 36
then domoticz.devices('Feinstaubbelastung EG').updateAlertSensor(domoticz.ALERTLEVEL_YELLOW, 'leicht erhöht, eventuell Lüften')
    
elseif domoticz.devices('Feinstaubsensor EG').sensorValue <= 35
then domoticz.devices('Feinstaubbelastung EG').updateAlertSensor(domoticz.ALERTLEVEL_GREEN, 'gering keine besonderen Maßnahmen nötig')

end
end
    }
    
Did anyone has an Idea here?

//
clemens

Re: Question regarding Value of Ikea Air quality Sensor

Posted: Monday 14 February 2022 16:15
by rwblinn
Hi,

tested the script below = ensure to assign your IDX for the two devices.

Code: Select all

-- IDX of the sensors used (ADJUST)
local IDX_AIR_SENSOR = 40         -- Name Feinstaubsensor EG
local IDX_ALERT_SENSOR = 26     -- Name Feinstaubbelastung EG
-- Timer rule - for tests use 'every minute'
local TIMER_RULE = 'every minute between 00:10 and 23:50'

return {
    active = true,
    on = {
        timer = { TIMER_RULE}
    },
    execute = function(domoticz, triggeredItem)
        local value = domoticz.devices(IDX_AIR_SENSOR).sensorValue
        if value >= 80 then 
           domoticz.devices(IDX_ALERT_SENSOR).updateAlertSensor(domoticz.ALERTLEVEL_RED, 'stark erhöht, FFP2 oder FFP3 Maske anziehen')
           local msg = ('Achtung stark erhöhte Feinstaubwerte, es könnte auch ein Feuer sein: %.f Partikel Dichte'):format(value)
           domoticz.log(msg)
	   domoticz.email('Feinstaubbelastung EG', msg, '[email protected]')
        elseif value > 35 and value < 80 then
            domoticz.devices(IDX_ALERT_SENSOR).updateAlertSensor(domoticz.ALERTLEVEL_YELLOW, 'leicht erhöht, eventuell Lüften')
        elseif value <= 35 then 
            domoticz.devices(IDX_ALERT_SENSOR).updateAlertSensor(domoticz.ALERTLEVEL_GREEN, 'gering keine besonderen Maßnahmen nötig')
        end
    end
}

Re: Question regarding Value of Ikea Air quality Sensor

Posted: Tuesday 15 February 2022 9:31
by mastadook
rwblinn wrote: Monday 14 February 2022 16:15 Hi,

tested the script below = ensure to assign your IDX for the two devices.

Code: Select all

-- IDX of the sensors used (ADJUST)
local IDX_AIR_SENSOR = 40         -- Name Feinstaubsensor EG
local IDX_ALERT_SENSOR = 26     -- Name Feinstaubbelastung EG
-- Timer rule - for tests use 'every minute'
local TIMER_RULE = 'every minute between 00:10 and 23:50'

return {
    active = true,
    on = {
        timer = { TIMER_RULE}
    },
    execute = function(domoticz, triggeredItem)
        local value = domoticz.devices(IDX_AIR_SENSOR).sensorValue
        if value >= 80 then 
           domoticz.devices(IDX_ALERT_SENSOR).updateAlertSensor(domoticz.ALERTLEVEL_RED, 'stark erhöht, FFP2 oder FFP3 Maske anziehen')
           local msg = ('Achtung stark erhöhte Feinstaubwerte, es könnte auch ein Feuer sein: %.f Partikel Dichte'):format(value)
           domoticz.log(msg)
	   domoticz.email('Feinstaubbelastung EG', msg, '[email protected]')
        elseif value > 35 and value < 80 then
            domoticz.devices(IDX_ALERT_SENSOR).updateAlertSensor(domoticz.ALERTLEVEL_YELLOW, 'leicht erhöht, eventuell Lüften')
        elseif value <= 35 then 
            domoticz.devices(IDX_ALERT_SENSOR).updateAlertSensor(domoticz.ALERTLEVEL_GREEN, 'gering keine besonderen Maßnahmen nötig')
        end
    end
}
Great, works like it should.
Thank you for your help.

//Clemens

Re: Question regarding Value of Ikea Air quality Sensor

Posted: Wednesday 16 February 2022 14:55
by mastadook
...
some Hours later: is it maybe possible to write the Value also back to the IDX_ALERT_SENSOR

Code: Select all

domoticz.devices(IDX_ALERT_SENSOR).updateAlertSensor(domoticz.ALERTLEVEL_RED, 'stark erhöht, %.f '):format(value)
did not work, got Error NIL Value again

Re: Question regarding Value of Ikea Air quality Sensor

Posted: Tuesday 22 March 2022 10:45
by rwblinn
Oops, rather late reply as not frequently using the Domoticz forum.
To update the alert sensor text, best to define a msg string and set as parameter. Something like (not tested):

Code: Select all

local msg = ('stark erhöht, %.f'):format(value)
domoticz.devices(IDX_ALERT_SENSOR).updateAlertSensor(domoticz.ALERTLEVEL_RED, msg)