A Forum run by Enthusiasts of MidNite Solar

The Open Source software/hardware corner => Node Red => Topic started by: Vic on June 08, 2018, 08:04:40 PM

Title: Node-Red, a High-Level Program/Device Development Tool
Post by: Vic 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
Title: Re: Node-Red, a High-Level Program/Device Development Tool
Post by: ClassicCrazy 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
Title: Re: Node-Red, a High-Level Program/Device Development Tool
Post by: ClassicCrazy 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
Title: Re: Node-Red, a High-Level Program/Device Development Tool
Post by: bee88man 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)
Title: Re: Node-Red, a High-Level Program/Device Development Tool
Post by: ricardo 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)
Title: Re: Node-Red, a High-Level Program/Device Development Tool
Post by: ricardo 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.
Title: Re: Node-Red, a High-Level Program/Device Development Tool
Post by: ClassicCrazy 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

Title: Re: Node-Red, a High-Level Program/Device Development Tool
Post by: ricardo 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.

Title: Re: Node-Red, a High-Level Program/Device Development Tool
Post by: ClassicCrazy 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
Title: Re: Node-Red, a High-Level Program/Device Development Tool
Post by: ricardo 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.
Title: Re: Node-Red, a High-Level Program/Device Development Tool
Post by: ClassicCrazy on June 17, 2018, 11:43:09 AM
Nice - I will have to get back on this project !

Larry
Title: Re: Node-Red, a High-Level Program/Device Development Tool
Post by: ClassicCrazy 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
Title: Re: Node-Red, a High-Level Program/Device Development Tool
Post by: ClassicCrazy on June 21, 2018, 09:17:46 PM
Quote from: ricardo 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.

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
Title: Re: Node-Red, a High-Level Program/Device Development Tool
Post by: ricardo 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}]
Title: Re: Node-Red, a High-Level Program/Device Development Tool
Post by: ClassicCrazy 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
Title: Re: Node-Red, a High-Level Program/Device Development Tool
Post by: ricardo on June 22, 2018, 09:50:44 PM
The programming bit is what i do for a living, so let me know if i can help.
Title: Re: Node-Red, a High-Level Program/Device Development Tool
Post by: ClassicCrazy on June 22, 2018, 10:27:55 PM
Quote from: ricardo on June 22, 2018, 09:50:44 PM
The programming bit is what i do for a living, so let me know if i can help.

Thanks - I figured you were a pro ! Sharing that already helped . I looked at your CSV and see how you did that.  I had tried CSV and nothing was coming through so I must have not had it set up right. I will give it another try later since I can reference yours as an example.  Sure wish you had a Classic !  Then you could be digging into the modbus.  Nice thing about the Classic and the modbus is that you can do a lot more to control with it - and write to it. Have you looked at Will's EV charging project in the Arduino section ?  He has done quite a bit using the Arduino  and documented it.

Larry
Title: Re: Node-Red, a High-Level Program/Device Development Tool
Post by: bee88man on June 23, 2018, 12:41:42 PM
I'm a total noob to most all of this, but find it all to be intriguing. I'll be watching with great intrest as this all that developes here and over at the Arduino threads, as I have a emonPi from OEM coming from the UK with Node-Red and MQTT loaded on SD.

Also have another unit coming soon to divert any/all PV Export into resistance load...immersion water heating using the Arduino w/ controlled burst mode..

As I understand it, no modbus is used, so that's not an option. Both can use wireless serial comm...will see how that part works out. ;)

Everyone needs a starting point, so this is mine.  :D
Title: Re: Node-Red, a High-Level Program/Device Development Tool
Post by: ClassicCrazy on June 23, 2018, 10:33:12 PM
Quote from: bee88man on June 23, 2018, 12:41:42 PM
I'm a total noob to most all of this, but find it all to be intriguing. I'll be watching with great intrest as this all that developes here and over at the Arduino threads, as I have a emonPi from OEM coming from the UK with Node-Red and MQTT loaded on SD.

Also have another unit coming soon to divert any/all PV Export into resistance load...immersion water heating using the Arduino w/ controlled burst mode..

As I understand it, no modbus is used, so that's not an option. Both can use wireless serial comm...will see how that part works out. ;)

Everyone needs a starting point, so this is mine.  :D

Let us know how it goes.

Larry