[SOLVED] Pull data from Node-red Topic is solved

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
Andrex
Posts: 92
Joined: Thursday 18 February 2016 9:11
Target OS: Linux
Domoticz version:
Contact:

[SOLVED] Pull data from Node-red

Post 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
Last edited by Andrex on Monday 07 November 2016 9:34, edited 1 time in total.
mgugu
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

Post 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
sj3fk3
Posts: 23
Joined: Sunday 22 March 2015 6:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Pull data from Node-red

Post 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?
mgugu
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

Post by mgugu »

No, I use os.execute("your Mosquitto command")
Andrex
Posts: 92
Joined: Thursday 18 February 2016 9:11
Target OS: Linux
Domoticz version:
Contact:

Re: Pull data from Node-red

Post 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
Andrex
Posts: 92
Joined: Thursday 18 February 2016 9:11
Target OS: Linux
Domoticz version:
Contact:

Re: Pull data from Node-red

Post by Andrex »

I've found the answer, it was right in the manual... :oops:

Code: Select all

/json.htm?type=devices&rid=IDX
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
Nautilus
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

Post by Nautilus »

Andrex wrote:I've found the answer, it was right in the manual... :oops:

Code: Select all

/json.htm?type=devices&rid=IDX
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]
Andrex
Posts: 92
Joined: Thursday 18 February 2016 9:11
Target OS: Linux
Domoticz version:
Contact:

Re: Pull data from Node-red

Post by Andrex »

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;
gives me

Code: Select all

TypeError: Cannot read property 'Status' of undefined
Andrex
Posts: 92
Joined: Thursday 18 February 2016 9:11
Target OS: Linux
Domoticz version:
Contact:

Re: Pull data from Node-red

Post by Andrex »

Solved, it was 0 and not 1

Code: Select all

msg.payload.result[0].Status;
Thanks Nautilus!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest