Page 1 of 1
[SOLVED] Pull data from Node-red
Posted: Wednesday 02 November 2016 14:59
by Andrex
How can I pull switches and sensors data from Node-red?
When a RaspberryPi, all the GPIOs are off course off, I need to ask DomoticZ what was the last known state of these GPIOs.
I also need this for the thermostat since the remote RaspberryPi receives the min and max temperature set points only when these are setup, so when the RaspberryPi restart, it doesn't have this info.
Thanks!
Andrea
Re: Pull data from Node-red
Posted: Saturday 05 November 2016 8:13
by mgugu
Suggest to use MQTT protocol.
You have to create a MQTT subscriber in node-red, install MQTT server somewhere (Mosquitto for example) and optionally a MQTT client on your Domoticz platform.
At domoticz level you have 2 solutions to distribute your devices data:
- Use the Domoticz MQTT support (you will have to create new hardware in Domo)
- Use LUA to send commands to the MQTT client, this is the solution I selected because more flexible (topic name, devices filtering,...). It should work also with blockly but I have not tested
Re: Pull data from Node-red
Posted: Saturday 05 November 2016 9:41
by sj3fk3
mgugu wrote:Suggest to use MQTT protocol.
- Use LUA to send commands to the MQTT client, this is the solution I selected because more flexible (topic name, devices filtering,...). It should work also with blockly but I have not tested
Did you use a lua mqtt library? If so, can you point me to it?
Re: Pull data from Node-red
Posted: Saturday 05 November 2016 9:54
by mgugu
No, I use os.execute("your Mosquitto command")
Re: Pull data from Node-red
Posted: Sunday 06 November 2016 11:59
by Andrex
mgugu wrote:Suggest to use MQTT protocol.
- Use the Domoticz MQTT support (you will have to create new hardware in Domo)
- Use LUA to send commands to the MQTT client, this is the solution I selected because more flexible (topic name, devices filtering,...). It should work also with blockly but I have not tested
But this is pushing data to Node-red, I need to pull the data: at boot Node-red will have to ask for the state of the switches to Domoticz
Re: Pull data from Node-red
Posted: Sunday 06 November 2016 20:31
by Andrex
I've found the answer, it was right in the manual...
Now the problem is that I can't parse the result in Node-red.
I've the following result from the json.htm request:
Code: Select all
{
"ActTime" : 1478456659,
"ServerTime" : "2016-11-06 19:24:19",
"Sunrise" : "07:12",
"Sunset" : "17:02",
"result" : [
{
"AddjMulti" : 1.0,
"AddjMulti2" : 1.0,
"AddjValue" : 0.0,
"AddjValue2" : 0.0,
"BatteryLevel" : 255,
"CustomImage" : 0,
"Data" : "Off",
"Description" : "",
"Favorite" : 1,
"HardwareID" : 8,
"HardwareName" : "Dummy",
"HardwareType" : "Dummy (Does nothing, use for virtual switches only)",
"HardwareTypeVal" : 15,
"HaveDimmer" : true,
"HaveGroupCmd" : true,
"HaveTimeout" : false,
"ID" : "00014071",
"Image" : "Light",
"IsSubDevice" : false,
"LastUpdate" : "2016-11-06 19:11:22",
"Level" : 0,
"LevelInt" : 0,
"MaxDimLevel" : 100,
"Name" : "Luce Cucina",
"Notifications" : "false",
"PlanID" : "0",
"PlanIDs" : [ 0 ],
"Protected" : false,
"ShowNotifications" : true,
"SignalLevel" : "-",
"Status" : "Off",
"StrParam1" : "",
"StrParam2" : "",
"SubType" : "Switch",
"SwitchType" : "On/Off",
"SwitchTypeVal" : 0,
"Timers" : "false",
"Type" : "Light/Switch",
"TypeImg" : "lightbulb",
"Unit" : 1,
"Used" : 1,
"UsedByCamera" : false,
"XOffset" : "0",
"YOffset" : "0",
"idx" : "33"
}
],
"status" : "OK",
"title" : "Devices"
}
I can get the value of the "first level" (ActTime, ServerTime, ...), but not the value inside the square brackets.
Any hint?
Thanks!!!
Andrea
Re: Pull data from Node-red
Posted: Sunday 06 November 2016 23:25
by Nautilus
Andrex wrote:I've found the answer, it was right in the manual...
Now the problem is that I can't parse the result in Node-red.
I've the following result from the json.htm request:
Code: Select all
{
"ActTime" : 1478456659,
"ServerTime" : "2016-11-06 19:24:19",
"Sunrise" : "07:12",
"Sunset" : "17:02",
"result" : [
{
"AddjMulti" : 1.0,
"AddjMulti2" : 1.0,
"AddjValue" : 0.0,
"AddjValue2" : 0.0,
"BatteryLevel" : 255,
"CustomImage" : 0,
"Data" : "Off",
"Description" : "",
"Favorite" : 1,
"HardwareID" : 8,
"HardwareName" : "Dummy",
"HardwareType" : "Dummy (Does nothing, use for virtual switches only)",
"HardwareTypeVal" : 15,
"HaveDimmer" : true,
"HaveGroupCmd" : true,
"HaveTimeout" : false,
"ID" : "00014071",
"Image" : "Light",
"IsSubDevice" : false,
"LastUpdate" : "2016-11-06 19:11:22",
"Level" : 0,
"LevelInt" : 0,
"MaxDimLevel" : 100,
"Name" : "Luce Cucina",
"Notifications" : "false",
"PlanID" : "0",
"PlanIDs" : [ 0 ],
"Protected" : false,
"ShowNotifications" : true,
"SignalLevel" : "-",
"Status" : "Off",
"StrParam1" : "",
"StrParam2" : "",
"SubType" : "Switch",
"SwitchType" : "On/Off",
"SwitchTypeVal" : 0,
"Timers" : "false",
"Type" : "Light/Switch",
"TypeImg" : "lightbulb",
"Unit" : 1,
"Used" : 1,
"UsedByCamera" : false,
"XOffset" : "0",
"YOffset" : "0",
"idx" : "33"
}
],
"status" : "OK",
"title" : "Devices"
}
I can get the value of the "first level" (ActTime, ServerTime, ...), but not the value inside the square brackets.
Any hint?
Thanks!!!
Andrea
maybe: result[1].Status
When there is [] you need to point to it with e.g. [1]
Re: Pull data from Node-red
Posted: Monday 07 November 2016 9:01
by Andrex
Nautilus wrote:maybe: result[1].Status
When there is [] you need to point to it with e.g. [1]
gives me
Code: Select all
TypeError: Cannot read property 'Status' of undefined
Re: Pull data from Node-red
Posted: Monday 07 November 2016 9:33
by Andrex
Solved, it was 0 and not 1
Thanks Nautilus!