Describe the bug
When using Carbonmonoxide or Carbondioxide sensor node, the Service will work in openHAB, but it will not show the current and peak levels (injected).
Expected behavior
Show the current/peak level in the device page.
Can someone confirm this for me? Or maybe I'm missing something?
As per my understanding the home.app doesn鈥檛 show the levels on the icons (different than for temperature). EVE app for example displays both on the sub page of a sensor like home.app does it as well in the property screen of an accessory. So my assumption is: works as design and not a bug.
@djiwondee Thanks! I know that it doesn't show on the values on the icon. But it doesn't show the values also when I click on the Details/Settings.
Like this:
There is no values next to the ppm...
Hello @radokristof,
if it is helpful for you here are my flow:
[{"id":"2c29863f.a39bba","type":"comment","z":"2b034a6e.a0f896","name":"Event Notification for CO2 Peak Level","info":"","x":1210,"y":380,"wires":[]},{"id":"4107cc85.6ed63c","type":"homekit-service","z":"2b034a6e.a0f896","bridge":"e933973b.f891d","name":"CO2 Sensor Living Room","serviceName":"CarbonDioxideSensor","topic":"","manufacturer":"Default Manufacturer","model":"Default Model","serialNo":"Default Serial Number","characteristicProperties":"{\n \"CarbonDioxideLevel\" : 0,\n \"CarbonDioxidePeakLevel\": 1000,\n \"CarbonDioxideDetected\" : 0,\n \"StatusActive\" : true\n}","x":1170,"y":540,"wires":[[]]},{"id":"6f3cd3e1.64dcbc","type":"function","z":"2b034a6e.a0f896","name":"Detect Highest Value","func":"var currentCo2PeakLevel = context.get('lastCo2PeakLevel') || 0;\n\nvar newMsg = {};\nnewMsg.payload = {\n \"CarbonDioxidePeakLevel\" : currentCo2PeakLevel,\n \"CarbonDioxideDetected\" : 0\n};\n\n// Check new Peak-Level\nif (msg.payload.CarbonDioxideLevel > currentCo2PeakLevel) {\n context.set('lastCo2PeakLevel', newMsg.payload.CarbonDioxideLevel);\n newMsg.payload.CarbonDioxidePeakLevel = msg.payload.CarbonDioxideLevel;\n}\n\n// Check Peak in critical level\nif (msg.payload.CarbonDioxideLevel >= 1000) {\n newMsg.payload.CarbonDioxideDetected = 1;\n} \n\nreturn newMsg;","outputs":1,"noerr":0,"x":1160,"y":420,"wires":[["8ab248aa.ca264"]]},{"id":"238c716.5eead8e","type":"change","z":"2b034a6e.a0f896","name":"Reset Payload for HkMsg CO2","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"CarbonDioxidePeakLevel\":null,\"CarbonDioxideDetected\":0}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":540,"wires":[["4107cc85.6ed63c"]]},{"id":"423bf4c0.7fbb7c","type":"change","z":"2b034a6e.a0f896","name":"Set payload to HkMsg CO2","rules":[{"t":"move","p":"payload.devices[0].dashboard_data.CO2","pt":"msg","to":"payload.CarbonDioxideLevel","tot":"msg"},{"t":"move","p":"payload.devices[0].reachable","pt":"msg","to":"payload.StatusActive","tot":"msg"},{"t":"delete","p":"payload.devices","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":480,"wires":[["4107cc85.6ed63c","6f3cd3e1.64dcbc"]]},{"id":"8ab248aa.ca264","type":"trigger","z":"2b034a6e.a0f896","op1":"","op2":"{\"CarbonDioxideDetected\" : 0}","op1type":"pay","op2type":"json","duration":"30","extend":false,"units":"s","reset":"","bytopic":"all","name":"Reset Detection after 30 sec","x":1180,"y":480,"wires":[["4107cc85.6ed63c"]]},{"id":"e933973b.f891d","type":"homekit-bridge","z":"","bridgeName":"Node-Red-HAP-Bridge-01","pinCode":"111-11-111","port":"","allowInsecureRequest":false,"manufacturer":"Default Manufacturer","model":"Default Model","serialNo":"Default Serial Number"}]

It is just the subset of the relevant code but showing all properties of the home kit node as well as coding for peak level detection and reset of that. It works really quite well.

My data source is a Netatmo weather stations. So the payload coming from there is adjusted by the node before injection into home kit.
For the child room I have a second sensor attached to Netatmo base station. In addition to CO2, Humidity and Temperature, I've added Battery Services. Same is linked to all climatic sensors:



I can confirm the bug still exists. Used the sample code from 'Example Carbon Dioxide Sensor' wiki page, and while peak level triggers ios notifications, the actual level and peak level not being displayed.
UPDATE: resolved myself, my CO2 sensor submits the values as string (not number) so the node-red logics works but homekit does not understand string values for ppm
@dmit2k
According to docs for Carbon Dioxide Sensor:
Carbon Dioxide Level value format is float (0 to 100000)
So it's an issue with your node-red logic and not with HomeKit itself :)
You have to just parse string to float which you suposetly did already.
@radokristof can you confirm if it's resolved for you aswell?
@Shaquu
Yes, exactly, but I would suggest to add string to number conversion into example as this may confuse people not familiar with such nuances.
Also one more question:
in your example you trigger alarm off after 30 sec manually. Why you do this?
IMHO the following change to your function is more logical:
// Check Peak in critical level
if (msg.payload.CarbonDioxideLevel >= 900) {
newMsg.payload.CarbonDioxideDetected = 1;
} else {
newMsg.payload.CarbonDioxideDetected = 0;
}
I would suggest to add string to number conversion into example
@dmit2k - you're welcome and invited to add your examples to the wiki page!
If you're not interested on doing that write up, paste your code in this thread and I'll add your example to the wiki page.
Thanks!
@crxporter
OK, will post my example code later. Was just curious why this 30sec trigger was used (just in case I missed something).
@Shaquu haven't had time to figure out this error, but maybe this was the problem for me! I will try it out.
I'll let @djiwondee speak for himself but for my smoke detectors I have a 1-minute reset trigger. For my system, this is used to clear the warning from the Home app.
Like everything else in this plugin, the beauty of it is that each user gets to set things exactly as they want!
Yes and you shouldn't forget that HomeKit is more or less just an interface for a home automation system so there is no logic provided (only the automation part maybe). So if you didn't reset triggered alarms/warnings it will stay there as long as you didn't explicitly "say" anything else.
Yes this solved the problem for me as well :) closing this issue.
OK, but I find it more useful to clear the alarm once the CO2 level goes down (and this is also more useful for automation). In my suggested change, it sends alarm-off trigger when level goes below preset value and so no trigger needed.
P.S. my CO2 sensor is a cheap ccs811 which produces lots of noice and values are too volatile, so I also had to add a filter for 'smoothing' the values:
// Applies a simple RC low pass filter to incoming payload values
var tc = 5*60*1000; // time constant in milliseconds
var lastValue = context.get('lastValue');
if (typeof lastValue == "undefined") lastValue = msg.payload;
var lastTime = context.get('lastTime') || null;
var now = new Date();
var currentValue = msg.payload;
if (lastTime === null) {
// first time through
newValue = currentValue;
} else {
var dt = now - lastTime;
var newValue;
if (dt > 0) {
var dtotc = dt / tc;
newValue = lastValue * (1 - dtotc) + currentValue * dtotc;
} else {
// no time has elapsed leave output the same as last time
newValue = lastValue;
}
}
context.set('lastValue', newValue);
context.set('lastTime', now);
msg.payload = newValue.toFixed(0);
return msg;
the beauty of it is that each user gets to set things exactly as they want!
Right now for my setup I'm working on a reset of the peak level notification triggered by a window contact sensor for the particular rooms. It would drive the need to let fresh air in the room for 10 minutes or so. Makes for sure mores sense rather than reset peak level automatically.
Plz reopen. CarbonDioxide works fine, but CarbonMonoxide ignores input and always shows current and peak at 100.
CarbonMonoxideDetected works fine.
What is the status of it on dev branch?
@ptath could you try this on separate node-red environment on dev version of our plugin?
I am closing this issue as it is old in might be a problem with hap-nodejs.
If you still have a problem (using NRCHKB 1.0.X) then please comment accordingly with more informations.
Most helpful comment
OK, but I find it more useful to clear the alarm once the CO2 level goes down (and this is also more useful for automation). In my suggested change, it sends alarm-off trigger when level goes below preset value and so no trigger needed.
P.S. my CO2 sensor is a cheap ccs811 which produces lots of noice and values are too volatile, so I also had to add a filter for 'smoothing' the values: