Page 1 of 2

Ikea vindriktning air quality sensor

Posted: Tuesday 10 August 2021 18:13
by redhouse
Hi all,

I took the idea of the Ikea vindriktning air quality sensor hack for home assistant and modified the code significantly to make it suitable to use with Domoticz. For those interested, please visit my github repository: https://github.com/marceldbo/VINDRIKTNI ... T-Domoticz

Since I use a Wemos D1 Mini, there are also pins enough to add other sensors e.g. BME/BMP280, DS18B20.

Enjoy and feel free to comment.

Re: Ikea vindriktning air quality sensor

Posted: Tuesday 10 August 2021 19:14
by waltervl
Perhaps also use the Alert Sensor Device to give an colored indication of the Air quality? https://www.domoticz.com/wiki/Domoticz_ ... ert_sensor

Re: Ikea vindriktning air quality sensor

Posted: Wednesday 11 August 2021 11:55
by redhouse
Interesting idea, indeed. I will have a look.

Re: Ikea vindriktning air quality sensor

Posted: Thursday 12 August 2021 10:54
by Jieffe
Nice work simplifying the original code. Whilst elegant, it was kind of hard to read and included a lot of useless stuff for us, Domoticz users. I intended to do the same as you did but you were faster :)

I still haven't visited my local Ikea to acquire the sensor but I'm already playing with the code.

I moved the config variables (ssid, password, ... ) to the Config.h tab and added a var for the Domoticz idx.

I also replaced Pubsubclient with ArduinoMqttClient/ArduinoJson but that's just a personal choice, the functionality is the same.

I noticed that you're updating the svalue but Domoticz is expecting the ppm value to be in the nvalue. Well, that's the way it works on my setup anyway (I temporarily hard-coded a value in the nvalue field for testing).

Re: Ikea vindriktning air quality sensor

Posted: Friday 13 August 2021 12:56
by redhouse
Moving the config variables to the config file was indeed also on my todo list :). The Ikea sensor provides values in ug/m3 and not ppm, because it is a generic sensor, measuring particles in the air at intervals. Ppm is typically used for specific sensors which measure the concentration of one type of gas with a specific weight, hence you can easily calculate the ppm. Converting the ug/m3 to ppm in case of the Ikea type of sensor is most likely going to provide you with unreliable values, as you would need to know the presence and percentage/concentration of each gas in your area and calculate the values accordingly.

The ArduinoMqttClient/ArduinoJson route is certainly a more elegant way of building the MQTT message. My solution was based on code I had already done for a different sensor ;)

By the way, I use a custom sensor in Domoticz so the svalue works fine. What sensor type are you using for your device?

Re: Ikea vindriktning air quality sensor

Posted: Friday 13 August 2021 18:08
by Jieffe
redhouse wrote: Friday 13 August 2021 12:56 The Ikea sensor provides values in ug/m3 and not ppm, because it is a generic sensor, measuring particles in the air at intervals.
I wasn't aware of that, thanks for the explanation !
redhouse wrote: Friday 13 August 2021 12:56 The ArduinoMqttClient/ArduinoJson route is certainly a more elegant way of building the MQTT message. My solution was based on code I had already done for a different sensor ;)
Same for me :) I already had written the MQTT code for other devices.
redhouse wrote: Friday 13 August 2021 12:56 By the way, I use a custom sensor in Domoticz so the svalue works fine. What sensor type are you using for your device?
I used the Air Quality sensor

Re: Ikea vindriktning air quality sensor

Posted: Thursday 19 August 2021 11:39
by mastadook
I have set up the Sensot with a 8622 D1 mini
all looks fine but I allways get a 0 Zero in the submitted Data.

Any Idea why?
I used Air Quality sensor
should I try with a Custom Sensor instead?
...

tried with Custom Senso, also Zero
It communicates but allways deliver a 0 in Data

Re: Ikea vindriktning air quality sensor

Posted: Thursday 19 August 2021 11:55
by waltervl
Do you send the correct data to Domoticz (nValue, sValue), see https://www.domoticz.com/wiki/Domoticz_ ... .2Fsensors for more information. MQTT uses the same definition as the API/Json calls.

Re: Ikea vindriktning air quality sensor

Posted: Thursday 19 August 2021 12:11
by freijn
mastadook wrote: Thursday 19 August 2021 11:39
Any Idea why?
I used Air Quality sensor
should I try with a Custom Sensor instead?
Yeah, to a custom sensor it works perfectly.

Re: Ikea vindriktning air quality sensor

Posted: Thursday 19 August 2021 12:12
by freijn
Anybody intrested to work with me to get this one in Tasmota or ESPeasy ?

Re: Ikea vindriktning air quality sensor

Posted: Thursday 19 August 2021 12:14
by mastadook
it send s {"idx":20373,"nvalue":0,"svalue":"0.00"}
I don´t know why?

Re: Ikea vindriktning air quality sensor

Posted: Thursday 19 August 2021 12:17
by waltervl
Then something is not right on your 8622 D1 mini code or hardware.

Re: Ikea vindriktning air quality sensor

Posted: Thursday 19 August 2021 14:21
by Jieffe
mastadook wrote: Thursday 19 August 2021 12:14 it send s {"idx":20373,"nvalue":0,"svalue":"0.00"}
I don´t know why?
Check your log in Domoticz. Does it says something along the lines "Invalid data received!" ?

I've got that error when setting up a MQ-7 sensor with an Air Quality sensor in Domoticz. Turns out Domoticz didn't want decimal in the JSON input, solved it by rounding the sensor data (or transform it into an int).

Re: Ikea vindriktning air quality sensor

Posted: Thursday 19 August 2021 14:59
by waltervl
Well the complaint was that 0 was seen in Domoticz. And now 0 was send. So if someone want to see the real value (eg 50) then you have to send 50 ;-)
And the nvalue and svalue are important. For an Airquality sensor you only send PPM as nvalue
For a custom sensor you have to send nvalue:0 and svalue:SENSORVALUE.
See wiki page https://www.domoticz.com/wiki/Domoticz_ ... .2Fsensors

Re: Ikea vindriktning air quality sensor

Posted: Thursday 19 August 2021 15:04
by freijn
mastadook wrote: Thursday 19 August 2021 12:14 it send s {"idx":20373,"nvalue":0,"svalue":"0.00"}
I don´t know why?
in = {"idx":4095,"nvalue":0,"svalue":"13.00"} is my datagram

What hardware (wemos, ESP ? ) are you using and on what pin have you connected the TX line coming from the sensor?

Re: Ikea vindriktning air quality sensor

Posted: Friday 20 August 2021 8:14
by mastadook
Thank you all for your help, I found MY Error!
I used PIN D3 instead of D2, so there was no Data delivered.
Looked and checked x Times and did not see it :oops:

Connect correctly, and yeah, it works, Great :)

Re: Ikea vindriktning air quality sensor

Posted: Friday 20 August 2021 13:17
by mastadook
Now, I like have a virtual switch showing the Status like a traffic light.
0-35 green
36-85 yellow
86 - ... red
I can´t find any virtual Device, that can help here.
Anyone with an Idea?
I like to Script something that will change the Switch Status.

Re: Ikea vindriktning air quality sensor

Posted: Friday 20 August 2021 15:03
by waltervl
mastadook wrote: Friday 20 August 2021 13:17 Now, I like have a virtual switch showing the Status like a traffic light.
0-35 green
36-85 yellow
86 - ... red
I can´t find any virtual Device, that can help here.
Anyone with an Idea?
I like to Script something that will change the Switch Status.
As mentioned before: Try the Alert Sensor
It is 5 levels: Grey, Green, Yellow, Orange, Red
You can add text to indicate the status
https://www.domoticz.com/wiki/Domoticz_ ... ert_sensor

Image

Re: Ikea vindriktning air quality sensor

Posted: Friday 20 August 2021 15:21
by mastadook
Great.
right now I´m still struggling with the dzvents Scripts reading and using the Sensor Data.
Whatever i try I got back that try to compare Nil with Number

Code: Select all

return {
	active = true,
	
	 on = { devices = {  'Feinstaubsensor EG','Feinstaubsensor Aussen','FSB'}},

	execute = function(domoticz, device, email)

if      tonumber(domoticz.devices('Feinstaubsensor EG').State) <= 35 then domoticz.devices('FSB').dimTo(0)
elseif  tonumber(domoticz.devices('Feinstaubsensor EG').State) > 36 < 85 then domoticz.devices('FSB').dimTo(10)
elseif  tonumber(domoticz.devices('Feinstaubsensor EG').State) >= 86 then domoticz.devices('FSB').dimTo(20)
end
end
    }
    

Code: Select all

2021-08-20 15:17:51.074 Status: dzVents: Info: Handling events for: "Feinstaubsensor EG", value: "14.00"
2021-08-20 15:17:51.074 Status: dzVents: Info: ------ Start internal script: FSBTest: Device: "Feinstaubsensor EG (MQTTSonoffServer)", Index: 20375
2021-08-20 15:17:51.074 Status: dzVents: Info: ------ Finished FSBTest
2021-08-20 15:17:51.074 Error: dzVents: Error: (3.1.7) An error occurred when calling event handler FSBTest
2021-08-20 15:17:51.074 Error: dzVents: Error: (3.1.7) ...i/domoticz/scripts/dzVents/generated_scripts/FSBTest.lua:8: attempt to compare nil with number
If the Base Script works, I may need to send this to my new Alert Sensor:
/json.htm?type=command&param=udevice&idx=20378&nvalue=1&svalue=gering%20keine%20besonderen%20Maßnahmen%20nötig

Re: Ikea vindriktning air quality sensor

Posted: Friday 20 August 2021 15:32
by waltervl
Why do you do that in dzVents?
You can do this directly from the code on the Wemos/Arduino/8622 D1 mini etc.
So have the code send the MQTT message for the custom sensor and have the code send an MQTT message for the alert sensor
Should be something like
{"idx":4095,"nvalue":0,"svalue":"90.00"} -- Custom sensor with value = 90.00
{"idx":201,"nvalue":"4","svalue":"Value 90 - Bad Air Quality"} -- Alert Sensor Red sign with text: "Value 90 - Bad Air Quality"