Page 2 of 2
Re: How to get this in domoticz
Posted: Monday 10 March 2025 19:49
by FireWizard
Good evening @edwin1234,
You said:
It
Works perfectly
I would say, it works (almost).
The svalue is in this case a fixed value of "0", which means "normal" .
See:
https://piandmore.wordpress.com/2019/02 ... -domoticz/
lv is the environment level which can have the following values:
0, normal
1, comfortable
2, dry
3, wet
So regardless of the "Humidity" in percent the environmental level is always normal.
About 5 years ago I created a kind of model for all weather sensors, which I recently updated to support newer Node-RED versions:
See:
viewtopic.php?p=263147&hilit=weather#p263147 My post 09 Dec 2020, 16:57.
And also:
viewtopic.php?p=323593&hilit=weather#p323593 My post 12 Feb 2025, 19:13
If you want to use that function, you should change the code in the "Function" node into the following:
Code: Select all
let hum_stat;
function comfortlevel(hum) {
switch (true) {
case hum > 70: { hum_stat = 3 } break;
case hum < 30: { hum_stat = 2 } break;
case hum >= 30 && hum <= 45: { hum_stat = 0 } break;
case hum > 45 && hum <= 70: { hum_stat = 1 } break;
default: { hum_stat = 0 } break;
}
return hum_stat;
}
let hu = msg.payload.humidity / 10;
let lv = comfortlevel(hu).toString();
msg.payload = { "command": "udevice", "idx": 1234, "nvalue":parseInt(hu), "svalue": lv};
return msg;
Let me know, if this works for you,
Regards
Re: How to get this in domoticz
Posted: Tuesday 11 March 2025 5:52
by edwin1234
Thanks for your update
Im gonna try this as soon as possible.
And let you know the results .
Re: How to get this in domoticz
Posted: Tuesday 11 March 2025 20:34
by edwin1234
Hi firewizard,
Can i copy this in to the function node or must i manualy type everything?
Cant find how to do this.
Re: How to get this in domoticz
Posted: Tuesday 11 March 2025 20:45
by FireWizard
Hi @edwin1234,
I would do it as follows:
1. Drag and drop a new "Function" node to the canvas.
2. Then go to the code block in my previous post and "SELECT ALL".
3. Ctrl-C
4. Open the new "Function" node and
5. Ctrl-V
6. Make your changes, as you did also previously.
7. Replace your old "Function" node with the new one.
Regards
Re: How to get this in domoticz
Posted: Wednesday 12 March 2025 10:40
by edwin1234
Thanks,
Now i see i have to do it with a laptop, i did it with copy paste on the ipad with the onscreen keyboard then you cant paste it in the function node.
Re: How to get this in domoticz
Posted: Saturday 15 March 2025 5:34
by edwin1234
Hi firewizard,
Must it be done like this?
Code: Select all
let hum_stat;
function comfortlevel(hum) {
switch (true) {
case hum > 70: { hum_stat = 3 } break;
case hum < 30: { hum_stat = 2 } break;
case hum >= 30 && hum <= 45: { hum_stat = 0 } break;
case hum > 45 && hum <= 70: { hum_stat = 1 } break;
default: { hum_stat = 0 } break;
}
return hum_stat;
}
let hu = msg.payload.data.dps["19"] / 10;
let lv = comfortlevel(hu).toString();
msg.payload = { "command": "udevice", "idx": 2381, "nvalue":parseInt(hu), "svalue": lv};
return msg;
Re: How to get this in domoticz
Posted: Saturday 15 March 2025 8:24
by FireWizard
Hi @edwin1234,
Must it be done like this?
Yes, that is correct, at least as the data, that you receive in msg.payload.data.dps["19"] is equal to a 3 digit number.e.g. 468, which would result in 46% humidity.
Regards
Re: How to get this in domoticz
Posted: Saturday 15 March 2025 8:34
by edwin1234
I did it like this
But for some reason it doesnt work?
Now i dont get the info into domoticz while it worked while it was like
This:
Code: Select all
msg.payload = { "command": "udevice", "idx": 2381, "svalue":"0","nvalue": parseInt (msg.payload.data.dps["19"] / 10)}
return msg;
Re: How to get this in domoticz
Posted: Saturday 15 March 2025 9:12
by FireWizard
Can you send me your flow?
Re: How to get this in domoticz
Posted: Saturday 15 March 2025 13:28
by edwin1234
I have send you the flow,
Your function node is not atached for now because it didnt work.
And its a bit a mess, but just for testing.
Re: How to get this in domoticz
Posted: Saturday 15 March 2025 18:01
by FireWizard
Hello @edwin1234,
I compared the contents of the "Function" node with the one in my "Test" flow.
The contents is equal, so no visible difference. For the moment it works for me, and I cannot explain, why it does not work for you.
As a reference I have attached my test flow.. Try this.
Code: Select all
[
{
"id": "4f2495cbd6e0cfec",
"type": "function",
"z": "a36df463ae2177b1",
"name": "function 6",
"func": "let hum_stat;\n\nfunction comfortlevel(hum) {\n \nswitch (true) {\n case hum > 70: { hum_stat = 3 } break;\n case hum < 30: { hum_stat = 2 } break;\n case hum >= 30 && hum <= 45: { hum_stat = 0 } break;\n case hum > 45 && hum <= 70: { hum_stat = 1 } break;\n default: { hum_stat = 0 } break;\n }\nreturn hum_stat;\n}\n\nlet hu = msg.payload.data.dps[\"19\"] / 10;\nlet lv = comfortlevel(hu).toString(); \n\nmsg.payload = { \"command\": \"udevice\", \"idx\": 2381, \"nvalue\":parseInt(hu), \"svalue\": lv};\n\nreturn msg;\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 920,
"y": 680,
"wires": [
[
"00dd07bac7137f6c"
]
]
},
{
"id": "6ba36bb6ce14b5d5",
"type": "inject",
"z": "a36df463ae2177b1",
"name": "",
"props": [
{
"p": "payload.data.dps[\"19\"]",
"v": "166",
"vt": "num"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 650,
"y": 680,
"wires": [
[
"4d1b8e518fd157b5",
"4f2495cbd6e0cfec"
]
]
},
{
"id": "4d1b8e518fd157b5",
"type": "debug",
"z": "a36df463ae2177b1",
"name": "debug 30",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 920,
"y": 740,
"wires": []
},
{
"id": "00dd07bac7137f6c",
"type": "debug",
"z": "a36df463ae2177b1",
"name": "debug 31",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1100,
"y": 680,
"wires": []
}
]
Regards
Re: How to get this in domoticz
Posted: Saturday 15 March 2025 20:51
by edwin1234
Thanks firewizard
I wil try it out en let you know
Regards
Re: How to get this in domoticz
Posted: Sunday 16 March 2025 16:37
by edwin1234
For some strange reason its working now.
Dont know how but that doesnt matter
Regards
Re: How to get this in domoticz
Posted: Sunday 16 March 2025 16:49
by FireWizard
Hello @edwin1234,
Good to hear.
It is something strange, I had it also.
When I connected "your Function" node to the same "Inject" node, your "Function" node
did not produce any output, while my original "Function" node (with the same contents) produced the expected output.
I disconnected my "Function" node and it started to work. I reconnected my "Function" node again and
got 2 identical outputs. Strange and I could not reproduce the error afterwards.
Okay, it is working now, so we leave it.
Regards