Python syntax question

Moderator: leecollings

Post Reply
manjh
Posts: 729
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Python syntax question

Post by manjh »

I am using Node-red to feed info into Domoticz devices. For this I have a function that composes the command for Domoticz:

Code: Select all

msg.payload = {"command":"udevice","idx":3678,"nvalue":0,"svalue":((msg.payload.svalue1).toString())};
In this example I update the single value of a device.
I am struggling to update a P1 Smart meter electric device, which contains six different values.
This does not seem difficult, Domoticz expects at least five values, separated by a semicolon.
But whatever I try, I can't seem to get it right!
Can someone put me on the right track?
Hans
manjh
Posts: 729
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python syntax question

Post by manjh »

Solved it. I first tried to set up the command using hardcoded values, played around a bit with the layout until Domoticz accepted the command.
Then found a way to convert the real values from the input payload of Node-Red into strings, adding the semi-colons.
The solution is perhaps not the most compact, but it works:

Code: Select all

    var temp = ((msg.payload.svalue1).toString())
    temp = temp.concat(";",((msg.payload.svalue2).toString()))
    temp = temp.concat(";",((msg.payload.svalue3).toString()))
    temp = temp.concat(";",((msg.payload.svalue4).toString()))
    temp = temp.concat(";",((msg.payload.svalue5).toString()))
    temp = temp.concat(";",((msg.payload.svalue6).toString()))
    msg.payload = {"command":"udevice","idx":3678,"nvalue":0,"svalue":temp};
Hans
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests