Author Topic: Node-Red, a High-Level Program/Device Development Tool  (Read 232 times)

Vic

  • Hero Member
  • *****
  • Posts: 1949
Node-Red, a High-Level Program/Device Development Tool
« on: June 08, 2018, 08:04:40 PM »
As a person who knows NOTHING of these things,   a reference was made in another Thread,  here,  to Node-Red.

Seemed that this reference belonged here,    else,   it might become lost.

Member,  jedon,  mentioned Node-Red,   in the following Thread on this Fourm:
http://midniteftp.com/forum/index.php?topic=3981.0

https://nodered.org/

Am not competent,  regarding the current state of the inexpensive  computer board thingies,   but the state of progress,   and the cost of the small board  computers/shields,  etc,   dazzles me.

Probably,  many here know all about tools,   such as Node-Red.

Just was trying to get this reference out of a relatively obscure Thread,    and hopefully,   to more generally accessible place here.

Amazin'   to me,    all of the Open-Source tools that are available.

Thanks to the Community that has contributed to ALL of this progress.

FWIW,   Vic
Off Grid - Two systems -- 4 SW+ 5548s, Surrette 4KS25 1280 AH X2@48V, 11.1 KW STC PV, 3X MidNite Classic 150 w/ WBjrs, Beta KID on S-530s, MX-60s, MN Bkrs/Boxes.  Thanks MN for Great Products/Service/Support!

ClassicCrazy

  • Hero Member
  • *****
  • Posts: 1762
Re: Node-Red, a High-Level Program/Device Development Tool
« Reply #1 on: June 08, 2018, 10:10:06 PM »
Yes from that mention in the other post I have been studying up on Node-Red.  It can be installed on Windows or a Raspberry Pi and other devices. It lets you build the programming control structure in a graphical form, and it can generate a webpage. So with it you can tie together many different devices .

Larry
system one
Classic 150 , 5s4p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system two
Classic 150 ,5s 135 watt Kyocero , 16s Calb 100AH LiFePO4 , Outback VFX 3648 inverter
system three
Midnite KID MPPT 24 DC in to  12 volt AGM batterie

ClassicCrazy

  • Hero Member
  • *****
  • Posts: 1762
Re: Node-Red, a High-Level Program/Device Development Tool
« Reply #2 on: June 08, 2018, 10:15:44 PM »
They all take some setup and geeky computer work  - nothing is super simple but if someone spends enough hours watching tutorials it is possible . I  got it installed on my Windows computer . Now to learn how to use it ! Here is a tutorial that shows some of the steps for Raspberry Pi . It wasn't that complicated to put on my Windows computer .
https://youtu.be/GeN7g4bdHiM

Larry
system one
Classic 150 , 5s4p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system two
Classic 150 ,5s 135 watt Kyocero , 16s Calb 100AH LiFePO4 , Outback VFX 3648 inverter
system three
Midnite KID MPPT 24 DC in to  12 volt AGM batterie

bee88man

  • Newby
  • *
  • Posts: 23
Re: Node-Red, a High-Level Program/Device Development Tool
« Reply #3 on: June 10, 2018, 09:11:39 AM »
Node-Red is one tool of many over at a relative open sourse forum named "Open Energy Monitor" ...amazing where all this can be applied...have a look. 8)

ricardo

  • Jr. Member
  • **
  • Posts: 54
Re: Node-Red, a High-Level Program/Device Development Tool
« Reply #4 on: June 10, 2018, 09:28:02 AM »
node red is a pretty good tool .. i use it on my grid tied PV install to gather up data points from different devices (APS ECU, Egauge, temp probe) and then send that data over to a series DB for storage.

i then use a graphing package to build my graphs (grafana). -- end result is pretty nice and reliable .. -- for ease of use i also laid down a messaging bus (mosquito) which is a bit of overkill, but lets me manage the whole thing from a single place.

Here is what my graphs look like.

(shows power demand, power generated, and temperature on one graph, and a monthly view of the same data)
« Last Edit: June 10, 2018, 09:29:55 AM by ricardo »

ricardo

  • Jr. Member
  • **
  • Posts: 54
Re: Node-Red, a High-Level Program/Device Development Tool
« Reply #5 on: June 10, 2018, 09:49:09 AM »
the power of node red is the high level functions that already exist which can be triggered by several methods (including periodically) .. and then if you need some custom programming , you can do it in javascript , which arguably is a simple language.

ClassicCrazy

  • Hero Member
  • *****
  • Posts: 1762
Re: Node-Red, a High-Level Program/Device Development Tool
« Reply #6 on: June 10, 2018, 09:51:16 AM »
Ricardo
I took a look at openhab - a bit of setup for my windows machine and deciding on cloud virtual machine , etc.
A lot of messing around to get it all setup .

I already have Node-Red setup on my windows computer.
What system do you use ? Windows, Linux  ?
Any suggestions for a beginner like me to make life easier in saving hours of setup time for stuff I may not need or use ?

Thanks,
Larry

system one
Classic 150 , 5s4p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system two
Classic 150 ,5s 135 watt Kyocero , 16s Calb 100AH LiFePO4 , Outback VFX 3648 inverter
system three
Midnite KID MPPT 24 DC in to  12 volt AGM batterie

ricardo

  • Jr. Member
  • **
  • Posts: 54
Re: Node-Red, a High-Level Program/Device Development Tool
« Reply #7 on: June 11, 2018, 12:58:42 AM »
I'm using Linux .. i finally just got my PC Mode connection to the KID working .. (too bad the data is garbage in FW 1860 , waiting for a fix from midnite) -- but i can tell you that getting the serial data in node-red is easy peasy ..

I added a node for serial comms, then it took 10 seconds to tell it to open /dev/ttyUSB0 and voila i had the serial data every time the KID pushed it.

parsing the comma delimited string should be a simple task too.


ClassicCrazy

  • Hero Member
  • *****
  • Posts: 1762
Re: Node-Red, a High-Level Program/Device Development Tool
« Reply #8 on: June 11, 2018, 01:20:14 AM »
 
Glad you got it working on Node Red.
I just finally got a Sonoff switch working with the espeasy software. I was trying everything because the tutorial did not seem to be working for remote switching. Until it finally dawned on me that the relay would not work with my direct serial powering - I needed to connect 110v input to get the relay to work. Geez !  well I learned a few more things along the way.
Now I can start to figure out the node-red and mqtt stuff to see if I can get it working via that.
In case you are interested this is what I used - though I used the latest espeasy Mega development instead of old version 120 of espeasy like is in the tutorial. You can get the basic Sonoff for about $5 each on aliexpress from the official sonoff site.
https://rutg3r.com/sonoff-firmware-tutorial-to-esp-easy/
Larry
« Last Edit: June 11, 2018, 01:43:52 AM by ClassicCrazy »
system one
Classic 150 , 5s4p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system two
Classic 150 ,5s 135 watt Kyocero , 16s Calb 100AH LiFePO4 , Outback VFX 3648 inverter
system three
Midnite KID MPPT 24 DC in to  12 volt AGM batterie

ricardo

  • Jr. Member
  • **
  • Posts: 54
Re: Node-Red, a High-Level Program/Device Development Tool
« Reply #9 on: June 16, 2018, 09:57:20 AM »
my first pass at parsing the kid data with node-red .. i think i did a pretty bad job at keeping things optimized and simple . but it works --

the output of that node-red flow is to a message bus (mosquito) -- i have a separate flow that reads these messages and writes the payload to a series DB (influx) which i then can use in a dashboard.

ClassicCrazy

  • Hero Member
  • *****
  • Posts: 1762
Re: Node-Red, a High-Level Program/Device Development Tool
« Reply #10 on: June 17, 2018, 11:43:09 AM »
Nice - I will have to get back on this project !

Larry
system one
Classic 150 , 5s4p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system two
Classic 150 ,5s 135 watt Kyocero , 16s Calb 100AH LiFePO4 , Outback VFX 3648 inverter
system three
Midnite KID MPPT 24 DC in to  12 volt AGM batterie

ClassicCrazy

  • Hero Member
  • *****
  • Posts: 1762
Re: Node-Red, a High-Level Program/Device Development Tool
« Reply #11 on: June 19, 2018, 12:31:26 PM »
Best way to get a handle on how to setup and use Node Red is this tutorial.
https://randomnerdtutorials.com/sonoff-basic-switch-esp-easy-firmware-node-red/

Sonoff Basic switches are inexpensive so that is good thing to start off with.

Though I already had a lot of this installed already but the step by step looks exactly like I did.
Gave me a grasp of how to use Node Red - so at least I can switch the Sonoff on and off using a node red interface.
And to answer my own question to Ricardo in the other post - it does look like there is a way to share those dashboards since I copied and pasted in the one from the linked example

Larry
system one
Classic 150 , 5s4p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system two
Classic 150 ,5s 135 watt Kyocero , 16s Calb 100AH LiFePO4 , Outback VFX 3648 inverter
system three
Midnite KID MPPT 24 DC in to  12 volt AGM batterie

ClassicCrazy

  • Hero Member
  • *****
  • Posts: 1762
Re: Node-Red, a High-Level Program/Device Development Tool
« Reply #12 on: June 21, 2018, 09:17:46 PM »
my first pass at parsing the kid data with node-red .. i think i did a pretty bad job at keeping things optimized and simple . but it works --

the output of that node-red flow is to a message bus (mosquito) -- i have a separate flow that reads these messages and writes the payload to a series DB (influx) which i then can use in a dashboard.

Could you share your Node-Red template ? I have been playing around with it today a bit . I would love to see how you set all that up . Especially how you take the comma separated values and split them up to individual items for the dashboard.

Thanks,
Larry
system one
Classic 150 , 5s4p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system two
Classic 150 ,5s 135 watt Kyocero , 16s Calb 100AH LiFePO4 , Outback VFX 3648 inverter
system three
Midnite KID MPPT 24 DC in to  12 volt AGM batterie

ricardo

  • Jr. Member
  • **
  • Posts: 54
Re: Node-Red, a High-Level Program/Device Development Tool
« Reply #13 on: June 22, 2018, 11:22:12 AM »
I'm not very proud of this flow -- but here it is

separating the CSV (comma separated values) can be done by using the CSV node, the serial node is not included in the basic package and you'll need to install that . (search for node-red serial) . -- i then have a node to divide some values by 10, and compute some other fields (such as home power)

i think i'll rewrite this flow at some point, but since its working its not high in my priority list.

[{"id":"78be8252.9d7f8c","type":"serial in","z":"e8386f1a.3ce78","name":"KID PC Mode","serial":"e569896a.ee29e8","x":110,"y":120,"wires":[["ce8215a4.a2fb98","4dff1558.07927c"]]},{"id":"ce8215a4.a2fb98","type":"csv","z":"e8386f1a.3ce78","name":"","sep":",","hdrin":"","hdrout":"","multi":"one","ret":"\\n","temp":"batt_v,pv_v,pv_power,pv_kwh_generated,pv_ah_generated,batt_temp,batt_a,batt_soc,batt_ah_remaining,rest_status","x":270,"y":120,"wires":[["7805104e.91f54"]]},{"id":"7805104e.91f54","type":"function","z":"e8386f1a.3ce78","name":"massage data","func":"function getValueOrDefault(value, default_value) {\n    if (value != null) {\n        return value;\n    }\n    return default_value;\n}\n\nmsg.payload.batt_v = getValueOrDefault(msg.payload.batt_v, 0) / 10;\n\nmsg.payload.pv_v = getValueOrDefault(msg.payload.pv_v, 0) / 10;\n\nmsg.payload.pv_power = getValueOrDefault(msg.payload.pv_power, 0);\n\nmsg.payload.pv_kwh_generated = getValueOrDefault(msg.payload.pv_kwh_generated, 0) / 10;\n\nmsg.payload.pv_ah_generated = getValueOrDefault(msg.payload.pv_ah_generated, 0) / 10;\n\nmsg.payload.batt_temp = getValueOrDefault(msg.payload.batt_temp, 0) / 10;\n\nmsg.payload.batt_a = getValueOrDefault(msg.payload.batt_a, 0) / 10;\n\nmsg.payload.batt_soc = getValueOrDefault(msg.payload.batt_soc, 0);\n\nmsg.payload.batt_ah_remaining = getValueOrDefault(msg.payload.batt_ah_remaining, 0);\n\n// No need to divide status\n\nmsg.payload.batt_power = msg.payload.batt_a * msg.payload.batt_v;\nmsg.payload.batt_power_charge = 0;\nmsg.payload.batt_power_discharge = 0;\nif (msg.payload.batt_a > 0) {\n    msg.payload.batt_power_charge = msg.payload.batt_a * msg.payload.batt_v;\n} else {\n    msg.payload.batt_power_discharge = msg.payload.batt_a * msg.payload.batt_v;\n}\nif (msg.payload.pv_power > 0) {\n    msg.payload.house_power = msg.payload.pv_power - msg.payload.batt_power;\n} else {\n    msg.payload.house_power = 0 - msg.payload.batt_power;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":440,"y":120,"wires":[["be02f7de.8281c8"]]},{"id":"be02f7de.8281c8","type":"function","z":"e8386f1a.3ce78","name":"prepare data","func":"function round(value, precision) {\n    var multiplier = Math.pow(10, precision || 0);\n    return Math.round(value * multiplier) / multiplier;\n}\n\nfunction convertToF(value) {\n    return value * 1.8 + 32;\n}\n\nvar battery_volts_msg = { payload: {} };\nbattery_volts_msg.payload.value = msg.payload.batt_v;\nbattery_volts_msg.payload.source = \"kid\";\n\nvar pv_volts_msg = { payload: {} };\npv_volts_msg.payload.value = msg.payload.pv_v;\npv_volts_msg.payload.source = \"kid\";\n\nvar pv_power_msg = { payload: {} };\npv_power_msg.payload.value = msg.payload.pv_power;\npv_power_msg.payload.source = \"kid\"\n\nvar pv_kwh_generated_msg = { payload: {} };\npv_kwh_generated_msg.payload.value = msg.payload.pv_kwh_generated;\npv_kwh_generated_msg.payload.source = \"kid\"\n\nvar pv_ah_generated_msg = { payload: {} };\npv_ah_generated_msg.payload.value = msg.payload.pv_ah_generated;\npv_ah_generated_msg.payload.source = \"kid\"\n\nvar batt_temp_msg = { payload: {} };\nbatt_temp_msg.payload.value = round(convertToF(msg.payload.batt_temp), 1);\nbatt_temp_msg.payload.source = \"kid\"\n\nvar batt_a_msg = { payload: {} };\nbatt_a_msg.payload.value = msg.payload.batt_a;\nbatt_a_msg.payload.source = \"kid\"\n\nvar batt_soc_msg = { payload: {} };\nbatt_soc_msg.payload.value = msg.payload.batt_soc;\nbatt_soc_msg.payload.source = \"kid\"\n\nvar batt_ah_remaining_msg = { payload: {} };\nbatt_ah_remaining_msg.payload.value = msg.payload.batt_ah_remaining;\nbatt_ah_remaining_msg.payload.source = \"kid\"\n\nvar rest_status_msg = { payload: {} };\nrest_status_msg.payload.value = msg.payload.rest_status;\nrest_status_msg.payload.source = \"kid\"\n\nvar batt_power_msg = { payload: {} };\nbatt_power_msg.payload.value = round(msg.payload.batt_power, 0);\nbatt_power_msg.payload.source = \"kid\"\n\nvar batt_power_charge_msg = { payload: {} };\nbatt_power_charge_msg.payload.value = round(msg.payload.batt_power_charge, 0);\nbatt_power_charge_msg.payload.source = \"kid\"\n\nvar batt_power_discharge_msg = { payload: {} };\nbatt_power_discharge_msg.payload.value = round(msg.payload.batt_power_discharge, 0);\nbatt_power_discharge_msg.payload.source = \"kid\"\n\nvar house_power_msg = { payload: {} };\nhouse_power_msg.payload.value = round(msg.payload.house_power, 0);\nhouse_power_msg.payload.source = \"kid\"\n\n\nreturn [\n    battery_volts_msg,\n    pv_volts_msg,\n    pv_power_msg,\n    pv_kwh_generated_msg,    \n    pv_ah_generated_msg,\n    batt_temp_msg,\n    batt_a_msg,\n    batt_soc_msg,\n    batt_ah_remaining_msg,\n    rest_status_msg,\n    batt_power_msg,\n    batt_power_charge_msg,\n    batt_power_discharge_msg,\n    house_power_msg\n]\n","outputs":"14","noerr":0,"x":130,"y":460,"wires":[["643bbad5.77d5c4"],["fae4c41d.f7df48"],["fefa4aa5.d15b38"],["947d8c42.dd45b"],["4679b8a3.106b68"],["e227806b.4d5c8"],["ad702663.ba5ec8"],["6245ad17.813c64"],["48df8e24.4d6d8"],["d7f9e988.a67a18"],["dcb195ee.bd1d38"],["a0ce8257.a361d"],["58fc6ef2.6d421"],["8471fa83.aa9fc8"]],"outputLabels":["batt_v","pv_v","","","","","","","","","","","",""]},{"id":"643bbad5.77d5c4","type":"template","z":"e8386f1a.3ce78","name":"set topic","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"home/offgrid/battery_voltage","output":"str","x":340,"y":220,"wires":[["a2528a13.9c4cf8"]]},{"id":"80ba5ec8.a21ac","type":"json","z":"e8386f1a.3ce78","name":"","pretty":false,"x":750,"y":420,"wires":[[]]},{"id":"6c7c12c8.170c7c","type":"catch","z":"e8386f1a.3ce78","name":"","scope":null,"x":700,"y":180,"wires":[["58c0e53e.bca02c"]]},{"id":"58c0e53e.bca02c","type":"debug","z":"e8386f1a.3ce78","name":"","active":true,"console":"false","complete":"false","x":854,"y":180.5,"wires":[]},{"id":"fae4c41d.f7df48","type":"template","z":"e8386f1a.3ce78","name":"set topic","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"home/offgrid/solar_voltage","output":"str","x":340,"y":260,"wires":[["a2528a13.9c4cf8"]]},{"id":"4dff1558.07927c","type":"debug","z":"e8386f1a.3ce78","name":"","active":true,"console":"false","complete":"false","x":310,"y":60,"wires":[]},{"id":"fefa4aa5.d15b38","type":"template","z":"e8386f1a.3ce78","name":"set topic","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"home/offgrid/solar_power","output":"str","x":340,"y":300,"wires":[["a2528a13.9c4cf8"]]},{"id":"947d8c42.dd45b","type":"template","z":"e8386f1a.3ce78","name":"set topic","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"home/offgrid/solar_kwh_generated","output":"str","x":340,"y":340,"wires":[["a2528a13.9c4cf8"]]},{"id":"4679b8a3.106b68","type":"template","z":"e8386f1a.3ce78","name":"set topic","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"home/offgrid/solar_ah_generated","output":"str","x":340,"y":380,"wires":[["a2528a13.9c4cf8"]]},{"id":"e227806b.4d5c8","type":"template","z":"e8386f1a.3ce78","name":"set topic","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"home/offgrid/battery_temperature","output":"str","x":340,"y":420,"wires":[["a2528a13.9c4cf8"]]},{"id":"ad702663.ba5ec8","type":"template","z":"e8386f1a.3ce78","name":"set topic","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"home/offgrid/battery_current","output":"str","x":340,"y":460,"wires":[["a2528a13.9c4cf8"]]},{"id":"48df8e24.4d6d8","type":"template","z":"e8386f1a.3ce78","name":"set topic","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"home/offgrid/battery_ah_remaining","output":"str","x":340,"y":540,"wires":[["a2528a13.9c4cf8"]]},{"id":"6245ad17.813c64","type":"template","z":"e8386f1a.3ce78","name":"set topic","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"home/offgrid/battery_soc","output":"str","x":340,"y":500,"wires":[["a2528a13.9c4cf8"]]},{"id":"d7f9e988.a67a18","type":"template","z":"e8386f1a.3ce78","name":"set topic","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"home/offgrid/controller_status","output":"str","x":340,"y":580,"wires":[["a2528a13.9c4cf8"]]},{"id":"a0ce8257.a361d","type":"template","z":"e8386f1a.3ce78","name":"set topic","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"home/offgrid/battery_power_charge","output":"str","x":340,"y":660,"wires":[["a2528a13.9c4cf8"]]},{"id":"8471fa83.aa9fc8","type":"template","z":"e8386f1a.3ce78","name":"set topic","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"home/offgrid/house_power","output":"str","x":340,"y":740,"wires":[["a2528a13.9c4cf8"]]},{"id":"58fc6ef2.6d421","type":"template","z":"e8386f1a.3ce78","name":"set topic","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"home/offgrid/battery_power_discharge","output":"str","x":340,"y":700,"wires":[["a2528a13.9c4cf8"]]},{"id":"dcb195ee.bd1d38","type":"template","z":"e8386f1a.3ce78","name":"set topic","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"home/offgrid/battery_power","output":"str","x":340,"y":620,"wires":[["a2528a13.9c4cf8"]]},{"id":"8ea51bdc.bbf7f8","type":"debug","z":"e8386f1a.3ce78","name":"","active":true,"console":"false","complete":"false","x":680,"y":560,"wires":[]},{"id":"a2528a13.9c4cf8","type":"function","z":"e8386f1a.3ce78","name":"sanity check","func":"if ((msg.payload.value >= 0) || (msg.payload.value <= 0)) {\n    // do nothing, the value is ok\n} else {\n    msg.payload.value = 0;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":570,"y":420,"wires":[["80ba5ec8.a21ac","8ea51bdc.bbf7f8"]]},{"id":"e569896a.ee29e8","type":"serial-port","z":"","serialport":"/dev/ttyUSB0","serialbaud":"57600","databits":"8","parity":"none","stopbits":"1","newline":"\\n","bin":"false","out":"char","addchar":false}]

ClassicCrazy

  • Hero Member
  • *****
  • Posts: 1762
Re: Node-Red, a High-Level Program/Device Development Tool
« Reply #14 on: June 22, 2018, 09:47:10 PM »
Thanks Ricardo - I will load up your flow and take a look at it .
I just watched a video on youtube where they showed how to get the code that you shared.
A little bit at a time  I may get it figured out . 

Larry
system one
Classic 150 , 5s4p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system two
Classic 150 ,5s 135 watt Kyocero , 16s Calb 100AH LiFePO4 , Outback VFX 3648 inverter
system three
Midnite KID MPPT 24 DC in to  12 volt AGM batterie