[SOLVED] Pull data from Node-red Topic is solved
Moderators: leecollings, remb0
[SOLVED] Pull data from Node-red
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
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
Last edited by Andrex on Monday 07 November 2016 9:34, edited 1 time in total.
-
- Posts: 220
- Joined: Friday 04 November 2016 12:33
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: France
- Contact:
Re: Pull data from Node-red
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
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
-
- Posts: 23
- Joined: Sunday 22 March 2015 6:41
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Pull data from Node-red
Did you use a lua mqtt library? If so, can you point me to it?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
-
- Posts: 220
- Joined: Friday 04 November 2016 12:33
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: France
- Contact:
Re: Pull data from Node-red
No, I use os.execute("your Mosquitto command")
Re: Pull data from Node-red
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 Domoticzmgugu 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
Re: Pull data from Node-red
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:
I can get the value of the "first level" (ActTime, ServerTime, ...), but not the value inside the square brackets.
Any hint?
Thanks!!!
Andrea

Code: Select all
/json.htm?type=devices&rid=IDX
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"
}
Any hint?
Thanks!!!
Andrea
-
- Posts: 722
- Joined: Friday 02 October 2015 12:12
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Finland
- Contact:
Re: Pull data from Node-red
maybe: result[1].StatusAndrex 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.Code: Select all
/json.htm?type=devices&rid=IDX
I've the following result from the json.htm request:I can get the value of the "first level" (ActTime, ServerTime, ...), but not the value inside the square brackets.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" }
Any hint?
Thanks!!!
Andrea
When there is [] you need to point to it with e.g. [1]
Re: Pull data from Node-red
Nautilus wrote:maybe: result[1].Status
When there is [] you need to point to it with e.g. [1]
Code: Select all
msg.payload.result[1].Status;
Code: Select all
TypeError: Cannot read property 'Status' of undefined
Re: Pull data from Node-red
Solved, it was 0 and not 1
Thanks Nautilus!
Code: Select all
msg.payload.result[0].Status;
Who is online
Users browsing this forum: Google [Bot] and 1 guest