Help with the lcd20x4-i2c node

So, I'm about as new as you can get with JavaScript and coding in general, so this might be tough, but please bear with me.
I'm getting data from two DHT-11 temperature and humidity sensors via a raspi 4 and am successfully controlling based on the 2 (4 total) values. The sensors each output their data to a full message as such:

{"topic":"rpi-dht11-tank1","payload":"16.00","_msgid":"20581305.994f1c","humidity":"67.00","isValid":true,"errors":0,"location":"DHT11 Tank 1","sensorid":"dht11"}

Each node's (useful) values are apparently being filtered and separated by two function blocks. One for the temperature reading:

msg.payload = msg.payload;
return msg;

The other for humidity reading;

msg.payload = msg.humidity;
return msg;
This setup appears to work fine and is controlling relays, lights and alarms perfectly.
Now the lcd node expects an object containing arrays as such:

{
msgs: [
{
msg: "string",
pos: number,
center: "boolean"
},
{
msg: "string",
pos: number,
center: "boolean"
},
]
};

I've gotten the screen to function and display properly, using a manually typed-in object from an inject node. Obviously, my goal here is to get those values coming out of the function node from the DHT-11 and get them into the {msg: "string"} location in the array of the lcd's object and monitor the values in real-time. Any help would be greatly appreciated. Thank you.

Apparently these intermediate steps are unnecessary, unless you use the intermediate data for some other purpose.

You can go from your input object to the final object with a simple template node (but there are many possible ways).

{
    "msgs": [
        {
            "msg": {{payload}},
            "pos": "number",
            "center": "boolean"
        },
        {
            "msg": {{humidity}},
            "pos": "number",
            "center": "boolean"
        }
    ]
}
[{"id":"72a605c2.2f300c","type":"debug","z":"5bbba54.8487b5c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":180,"wires":[]},{"id":"3e67a33c.b6986c","type":"template","z":"5bbba54.8487b5c","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n    \"msgs\": [\n        {\n            \"msg\": {{payload}},\n            \"pos\": \"number\",\n            \"center\": \"boolean\"\n        },\n        {\n            \"msg\": {{humidity}},\n            \"pos\": \"number\",\n            \"center\": \"boolean\"\n        }\n    ]\n}","output":"json","x":520,"y":180,"wires":[["72a605c2.2f300c"]]},{"id":"74909667.8b2718","type":"function","z":"5bbba54.8487b5c","name":"Dataset","func":"msg = {\n    \"topic\": \"rpi-dht11-tank1\",\n    \"payload\": \"16.00\",\n    \"_msgid\": \"20581305.994f1c\",\n    \"humidity\": \"67.00\",\n    \"isValid\": true,\n    \"errors\": 0,\n    \"location\": \"DHT11 Tank 1\",\n    \"sensorid\": \"dht11\"\n};\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":180,"wires":[["3e67a33c.b6986c"]]},{"id":"534d81ae.a0a8c","type":"inject","z":"5bbba54.8487b5c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":180,"wires":[["74909667.8b2718"]]}]

This did work, thank you very much. The template node needed to be set to Output as Parsed YAML, and the "msg": string needed to be in quotes. So like "msg": "{{payload}}",. That worked like a charm.

The only issue now is getting each sensor to output to its own section in the array. I was able to get them to display their own separate values on their own line with a change node, but its causing the display to just alternate between the values displayed on each line; it's not able to show everything at once.
This may be an issue to try to ask the developer of the lcd node, but I'd very much appreciate some ideas to make this more efficient. But your idea there, Andrei, put me way closer to a solution, thank you very much.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.