Use Node red to harvest data

Hi1
New user here. I just want to tip you about Node red: https://nodered.org/

A graphical tool that let you integrate your weather station with other applications in a very simple way:

image

Runs on a raspberry.

I’ve set up a udp listener and formated messages and inserted them in my home assistant installation, Which will display the observations.

Pretty simple. And fun!

Rgd’s
Mats

5 Likes

Hi, Mats,

That’s great information.

Welcome to the forum.

Gary

1 Like

Hello Mats

can’t find the flow … is it online ???

Hi!
My flow is local to my installation, so you cant access it in any way.
If you want i could copy it to you but it wouldnt make Sense becouse your integretation will be differerent.
Rgd’s
Mats

Thanks WF1,
It would be so helpful if you could share the flow via export - clipboard so I could use your UDP components of your example. Im not so sure how to process the UDP data and am trying to get my weather flow data into EmonCMS. Thanks for your time posting this! Cheers, Mike.

For anyone wanting to access the UDP messages in NodeRed, after looking at the above examples and spending some time working out message flows I’ve managed to get a working solution. Its not the most simple flow and I’m sure theres a better way to do it but take a look at my flow I’ve shared on Openenergymonotor forums to move data from the weather flow UDP to EmonCMS.


Hope this helps someone!
Thanks Mats for some guidance!
Cheers,
MikeC

1 Like

And here is my flow as well:

[{“id”:“f606f7f7.8206f8”,“type”:“tab”,“label”:“weatherflow”,“disabled”:false,“info”:""},{“id”:“3e97bc6f.ce0eb4”,“type”:“udp in”,“z”:“f606f7f7.8206f8”,“name”:“weatherflow”,“iface”:"",“port”:“50222”,“ipv”:“udp4”,“multicast”:“false”,“group”:"",“datatype”:“utf8”,“x”:90,“y”:400,“wires”:[[“6c93301f.1dd0c”]]},{“id”:“6c93301f.1dd0c”,“type”:“json”,“z”:“f606f7f7.8206f8”,“name”:"",“property”:“payload”,“action”:“obj”,“pretty”:false,“x”:230,“y”:400,“wires”:[[“88c44c4.ca9beb”]]},{“id”:“b4daec4.77c721”,“type”:“api-call-service”,“z”:“f606f7f7.8206f8”,“name”:“home assistant”,“server”:“1bbb5a5d.ccfaf6”,“service_domain”:“variable”,“service”:“set_variable”,“data”:"",“mergecontext”:"",“x”:880,“y”:400,“wires”:[[“78d0ec54.a17a34”]]},{“id”:“78d0ec54.a17a34”,“type”:“debug”,“z”:“f606f7f7.8206f8”,“name”:"",“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“payload”,“x”:1050,“y”:400,“wires”:},{“id”:“88c44c4.ca9beb”,“type”:“switch”,“z”:“f606f7f7.8206f8”,“name”:"",“property”:“payload.type”,“propertyType”:“msg”,“rules”:[{“t”:“eq”,“v”:“device_status”,“vt”:“str”},{“t”:“eq”,“v”:“hub_status”,“vt”:“str”},{“t”:“eq”,“v”:“obs_air”,“vt”:“str”},{“t”:“eq”,“v”:“obs_sky”,“vt”:“str”},{“t”:“else”}],“checkall”:“true”,“repair”:false,“outputs”:5,“x”:350,“y”:400,“wires”:[[“875d2fac.df206”],[“875d2fac.df206”],[“e73ca3b2.2eb4c”],[“c442ff16.353ff”],[“a9afd4fa.00de88”]],“outputLabels”:[“device status”,“hub status”,"","",""]},{“id”:“4c429d87.aed5e4”,“type”:“function”,“z”:“f606f7f7.8206f8”,“name”:“device status”,“func”:“var newmsg = { “payload”: { “data”: { “variable”: msg.payload.serial_number.toLowerCase(), “value”: msg.payload.rssi, “attributes”: msg.payload } } };\nreturn newmsg;”,“outputs”:1,“noerr”:0,“x”:670,“y”:340,“wires”:[[“b4daec4.77c721”]]},{“id”:“a9afd4fa.00de88”,“type”:“function”,“z”:“f606f7f7.8206f8”,“name”:“attr template”,“func”:“var newmsg = { “payload”: { “data”: { “variable”: msg.payload.type, “attributes”: msg.payload } } };\nreturn newmsg;”,“outputs”:1,“noerr”:0,“x”:670,“y”:460,“wires”:[[“b4daec4.77c721”]]},{“id”:“e73ca3b2.2eb4c”,“type”:“function”,“z”:“f606f7f7.8206f8”,“name”:“obs air”,“func”:“var newmsg = { “payload”: { “data”: { “variable”: msg.payload.type, “value”: msg.payload.obs[0][2], “attributes”: msg.payload } } };\nreturn newmsg;”,“outputs”:1,“noerr”:0,“x”:650,“y”:380,“wires”:[[“b4daec4.77c721”]]},{“id”:“c442ff16.353ff”,“type”:“function”,“z”:“f606f7f7.8206f8”,“name”:“obs sky”,“func”:“var newmsg = { “payload”: { “data”: { “variable”: msg.payload.type, “value”: msg.payload.obs[0][1], “attributes”: msg.payload } } };\nreturn newmsg;”,“outputs”:1,“noerr”:0,“x”:660,“y”:420,“wires”:[[“b4daec4.77c721”]]},{“id”:“875d2fac.df206”,“type”:“change”,“z”:“f606f7f7.8206f8”,“name”:“set variable”,“rules”:[{“t”:“change”,“p”:“msg.payload.serial_number”,“pt”:“msg”,“from”:"-",“fromt”:“str”,“to”:"_",“tot”:“str”}],“action”:"",“property”:"",“from”:"",“to”:"",“reg”:false,“x”:510,“y”:340,“wires”:[[“4c429d87.aed5e4”]]},{“id”:“1bbb5a5d.ccfaf6”,“type”:“server”,“z”:"",“name”:“Home Assistant”,“url”:“https://**",“pass”:"”}]

Feel free to improve :slight_smile:

Rgd’s
Mats

Helo Mats

just installed me a spare emoncms server and I started to look at your flow, but … I have 2 stations in test and I have the impression your flow listens to the UDP port regardless origin, so most probably I’m going to get both flows mixed …

as a novice in node-red I looked at the udp tab but couldn’t find any filter for incoming IP, if we could make it listen to port 50222 from ip xx and then set the flow again with the filter set to ip yy

possible ?

thanks for your time

eric

Hi!
Correct, it listens to all that comes on port 50222. And its not possible to fliter based on source ip in any way I know of.

in this case I Think I would do filtering based on hub serial number in a switch node (all messages from devices contains the serial number of the associated hub): if payload contains (hub serialnumber) x route to output 1, if payload contains y route to output 2. And build each station flow from there.

Good luck exploring :blush:

Rgds
Mats

Hi @wf1

I can’t import your flow, could you share it once more maybe something went wrong with copy/paste but the import button stays greyed out with your code.

Or could you explain some more what you do in your switch node and function nodes and how you send it to HASS ( i have the UDP part working)

I can maybe help you with my node-red

Beware I tweaked it so I can follow my 2 stations, but if you’re a bit ok with node-red, you’ll quickly understand how to re tweak it

weatherflow-nodered-emoncms.txt (24.6 KB)

Hi @eric thanks! But have the same problem, import stays greyed out (maybe it has something to do with node-red into hass - https://github.com/hassio-addons/addon-node-red/blob/v0.5.0/README.md)

Could you maybe describe / show in images what you do in the switch / function part and the HASS at the end because that is where i’m stuck at the moment

Hi!
It seems like pasting text does something with some characters… attaching a text file and hope it works better

anyhow. the switch node “admin” filters messages and sends them to different outputs depending wich unit (sky, air or hub) originates the message.

the change node “set variable” changes “-” in unit serial number to “_” (HA does not accept “-” in entity names)

the function nodes formats message payload to match the data field in HA call service node.

The HA call service node updates states in variables https://community.home-assistant.io/t/custom-component-to-declare-set-variables/25218

variable:
obs_air:
value: 0
restore: true
obs_sky:
value: 0
restore: true
rapid_wind:
value: 0
restore: true
evt_strike:
value: 0
restore: true
evt_precip:
value: 0
restore: true

The last thing (I do) is to define template sensors in configuration.yaml based on the variables:

  • platform: template
    sensors:
    weatherflow_pressure:
    friendly_name: ‘Lufttryck’
    unit_of_measurement: ‘hpa’
    value_template: ‘{{ states.variable.obs_air.attributes.obs[0][1] + 25.4 | round(1) }}’
    weatherflow_temperature:
    friendly_name: ‘Temperatur’
    unit_of_measurement: ‘°C’
    value_template: ‘{{ states.variable.obs_air.attributes.obs[0][2] }}’

good luck!

weather-flow.txt (3.3 KB)

Thanks @wf1 and @eric for the help, i got it working now in node-red. I have added “variable.py” to my custom_components but do i also need to add something in my config like below or is adding it as template under sensor enough?

Variable:
weatherflow_temperature

This because i’m seeing:

2018-08-15 22:09:55 INFO (MainThread) [homeassistant.components.http.view] Serving /api/services/variable/set_variable to xxx.xxx.xxx.xxx(auth: True)
2018-08-15 22:09:55 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=variable, service=set_variable, service_data=variable=obs_air, value=20.74, attributes=serial_number=AR-00010131, type=obs_air, hub_sn=HB-00005166, obs=[[1534363793, 1017.2, 20.74, 73, 0, 0, 2.96, 1]], firmware_revision=20>
2018-08-15 22:09:55 WARNING (MainThread) [custom_components.variable] Failed to set unknown variable: variable.obs_air

You have to declare your variables in configuration.yaml:

from https://github.com/rogro82/hass-variables
Configure
Add the component variable to your configuration and declare the variables you want.

Example configuration:

variable:
countdown_timer:
value: 30
attributes:
friendly_name: ‘Countdown’
icon: mdi:alarm
countdown_trigger:
name: Countdown
value: False
light_scene:
value: ‘normal’
attributes:
previous: ‘’
restore: true

A variable ‘should’ have a value and can optionally have a name and attributes, which can be used to specify additional values but can also be used to set internal attributes like icon, friendly_name etc.

In case you want your variable to restore its value after restarting you can set restore to true.