MQTT + Netatmo

Node RED related questions.
Post Reply
User avatar
martinhult
Posts: 8
Joined: Tue Sep 08, 2020 10:49 am
Location: Sweden
Contact:

MQTT + Netatmo

Post by martinhult »

Hey,

Since the weather functionality in the Robonect only talks to OpenWeatherMaps I had to try something else.
The weather station is located to far away for me to get an accurate weather status of where the machine is located.

Therefor I bought a Netatmo weather station with a rain gauge with my though of having this one talking to the robonect MQTT.

Since I'm a newbie on MQTT and NodeRED I'm reaching out to the ones who are better.

I want the NodeRED to speak to the machine and tell it to start cutting depending on the humidity situation.
If the humidity is let say over 80% then it should stay home. And is it under then it's ok to be in AUTO mode and cut grass.
Also if there's rain going on it shouldn't cut either.

Can someone point me in the right direction on how to solve this?
I do get out a full array from the netatmo weather station with all its data.

Hojj!

// Martin
Forum administrator - McCulloch R1000 + Robonect® Hx - 10p

Tamaz
Site Admin
Posts: 17
Joined: Tue Sep 08, 2020 10:45 am

Re: MQTT + Netatmo

Post by Tamaz »

Lets have a go!

The array of data, have you got that in Node-red already or do we need to start with a node to fetch the MQTT data?

User avatar
martinhult
Posts: 8
Joined: Tue Sep 08, 2020 10:49 am
Location: Sweden
Contact:

Re: MQTT + Netatmo

Post by martinhult »

The array from the weather station is connected and I get the data out from it.
It's right now a simple timestamp connected to the Netatmo Dashboard and to msg.paylod.

Code: Select all

[{"id":"416ecc90.fc5174","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"1820bf1c.d7ec01","type":"inject","z":"416ecc90.fc5174","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":140,"wires":[["86638f3a.9600c"]]},{"id":"86638f3a.9600c","type":"netatmo-dashboard","z":"416ecc90.fc5174","creds":"97d8241e.de65d8","x":340,"y":80,"wires":[["a818a8d.ebdf758"]]},{"id":"a818a8d.ebdf758","type":"debug","z":"416ecc90.fc5174","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":570,"y":80,"wires":[]},{"id":"97d8241e.de65d8","type":"netatmo-config-node","z":"","client_id":"xxxxxxxxxxxxxxx","client_secret":"xxxxxxxxxxxxxxxxx","username":"[email protected]","password":"xxx!"}]
array.jpg
You do not have the required permissions to view the files attached to this post.
Forum administrator - McCulloch R1000 + Robonect® Hx - 10p

Tamaz
Site Admin
Posts: 17
Joined: Tue Sep 08, 2020 10:45 am

Re: MQTT + Netatmo

Post by Tamaz »

Node-red is hard before you get a hold of its basics. I'm in no way an expert now, but when i were a beginner my biggest hardship came from not understanding the different data types passed between nodes, or how to access a specific bit of the data.

The debug node is your friend, it will always show you exactly what flows between nodes, and using two of them, one before and one after a node have been very useful to better understand what that node really do in a flow.

This video explains the most basic stuff, if you are just beginning with node-red its a good start:
https://www.youtube.com/watch?v=z-mwVUBhcL4

Tamaz
Site Admin
Posts: 17
Joined: Tue Sep 08, 2020 10:45 am

Re: MQTT + Netatmo

Post by Tamaz »

Doing this was a bit more complicated than i had anticipated! :roll:

Using the weather station data to figure out if the mower should mow or not is easy. But we probably don't want to spam command messages to the mower all the time, so it would be nice if we first could check what it's doing, and only send commands if we want to change its behavior. Doing this is not hard, but it gets a bit too complicated to guide you only through text.

Let me try to build a working flow for it, then i can post it here and explain what it's doing.

User avatar
martinhult
Posts: 8
Joined: Tue Sep 08, 2020 10:49 am
Location: Sweden
Contact:

Re: MQTT + Netatmo

Post by martinhult »

Appreciate it. Thanks!
Forum administrator - McCulloch R1000 + Robonect® Hx - 10p

Tamaz
Site Admin
Posts: 17
Joined: Tue Sep 08, 2020 10:45 am

Re: MQTT + Netatmo

Post by Tamaz »

So here is a flow to test.

It catches the mowers current mode from MQTT into a flow variable.

Every 10min it then gets weather data, and determines if the weather is good or not. It then checks current mower mode, and if its already in the right mode does nothing. If in the wrong mode for current weather, it sends a MQTT command to change the mode on the mower.

I've left the connections to the MQTT output node out to not cause any trouble.
Use the debug window to check results before connecting.

MQTT nodes need to be updated with correct MQTT broker, and base topic modified for whatever you specified in robonect.

Netamo node would also need to be added to node-red and configured.

I would assume modifying the property path for "is it too humid?" and "is there rain?" checks is also a requirement.

Hopefully this is close enough for you to modify it to your needs.
flow.GIF
Copy below code and paste it in the import function in Node-red:

Code: Select all

[{"id":"1dcd59e7.77491e","type":"get stations data","z":"91caa791.a492","name":"","creds":"9a43bf2b.42c99","x":190,"y":360,"wires":[["f4f5e6b6.393f58"]]},{"id":"f26bebf4.35c35","type":"inject","z":"91caa791.a492","name":"Run every 10min","topic":"","payload":"","payloadType":"date","repeat":"600","crontab":"","once":true,"onceDelay":0.1,"x":190,"y":240,"wires":[["7f79ee5a.4d201"]]},{"id":"f4f5e6b6.393f58","type":"switch","z":"91caa791.a492","name":"Is it too humid?","property":"payload.devices[0].modules[0].dashboard_data.Humidity","propertyType":"msg","rules":[{"t":"gt","v":"80","vt":"num"},{"t":"lte","v":"75","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":180,"y":420,"wires":[["790823e5.af430c","ef5d084e.de2f88"],["97ae8ccf.c4369"]]},{"id":"97ae8ccf.c4369","type":"switch","z":"91caa791.a492","name":"Is there rain?","property":"payload.devices[0].modules[1].dashboard_data.Rain","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":190,"y":500,"wires":[["6ac6ef0d.df1268","ef5d084e.de2f88"],["ddc0121b.02d9f","efee0a19.f3d9d"]]},{"id":"bd9ff90a.539688","type":"debug","z":"91caa791.a492","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1100,"y":380,"wires":[]},{"id":"790823e5.af430c","type":"change","z":"91caa791.a492","name":"Readable output","rules":[{"t":"set","p":"payload","pt":"msg","to":"To humid, send mower home.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":320,"wires":[["bd9ff90a.539688"]]},{"id":"6ac6ef0d.df1268","type":"change","z":"91caa791.a492","name":"Readable output","rules":[{"t":"set","p":"payload","pt":"msg","to":"Raining, send mower home","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":360,"wires":[["bd9ff90a.539688"]]},{"id":"6db38a20.cd7ffc","type":"mqtt out","z":"91caa791.a492","name":"Send command to mower","topic":"mower/control/mode","qos":"","retain":"true","broker":"2c54e5d1.9e495a","x":1100,"y":640,"wires":[]},{"id":"dc0db773.851ac8","type":"change","z":"91caa791.a492","name":"Change payload to HOME command","rules":[{"t":"set","p":"payload","pt":"msg","to":"home","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":620,"wires":[[]]},{"id":"be034ab6.a41138","type":"mqtt in","z":"91caa791.a492","name":"Catch mower mode from MQTT","topic":"mower/mower/mode","qos":"2","datatype":"auto","broker":"2c54e5d1.9e495a","x":180,"y":180,"wires":[["5a09569d.f1c36"]]},{"id":"5a09569d.f1c36","type":"change","z":"91caa791.a492","name":"Save mower mode to flow variable","rules":[{"t":"set","p":"mowermode","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":180,"wires":[[]]},{"id":"efee0a19.f3d9d","type":"switch","z":"91caa791.a492","name":"Is robot in auto mode?","property":"mowermode","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"neq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":660,"wires":[["9abcc6e0.3f4628"],["5246d915.424908","b6d4178c.11bee8"]]},{"id":"ddc0121b.02d9f","type":"change","z":"91caa791.a492","name":"Readable output","rules":[{"t":"set","p":"payload","pt":"msg","to":"Weather is good!","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":400,"wires":[["bd9ff90a.539688"]]},{"id":"5246d915.424908","type":"change","z":"91caa791.a492","name":"Change payload to AUTO command","rules":[{"t":"set","p":"payload","pt":"msg","to":"auto","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":660,"wires":[[]]},{"id":"ef5d084e.de2f88","type":"switch","z":"91caa791.a492","name":"Is robot in auto mode?","property":"mowermode","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"neq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":400,"y":540,"wires":[["dc0db773.851ac8","7d37b42a.f2e894"],["9e8f4667.c0aa3"]]},{"id":"9e8f4667.c0aa3","type":"change","z":"91caa791.a492","name":"Readable output","rules":[{"t":"set","p":"payload","pt":"msg","to":"Mower already stopped, not sending any command.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":440,"wires":[["bd9ff90a.539688"]]},{"id":"9abcc6e0.3f4628","type":"change","z":"91caa791.a492","name":"Readable output","rules":[{"t":"set","p":"payload","pt":"msg","to":"Mower already in auto, not sending any command.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":520,"wires":[["bd9ff90a.539688"]]},{"id":"b6d4178c.11bee8","type":"change","z":"91caa791.a492","name":"Readable output","rules":[{"t":"set","p":"payload","pt":"msg","to":"Mower stopped, sending auto command.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":480,"wires":[["bd9ff90a.539688"]]},{"id":"7d37b42a.f2e894","type":"change","z":"91caa791.a492","name":"Readable output","rules":[{"t":"set","p":"payload","pt":"msg","to":"Mower already in auto, sending home command.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":560,"wires":[["bd9ff90a.539688"]]},{"id":"7f79ee5a.4d201","type":"change","z":"91caa791.a492","name":"Get mower mode","rules":[{"t":"set","p":"mowermode","pt":"msg","to":"mowermode","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":190,"y":280,"wires":[["82dc0f08.bd2ec"]]},{"id":"82dc0f08.bd2ec","type":"switch","z":"91caa791.a492","name":"Check that saved mower mode contains data.","property":"mowermode","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":220,"y":320,"wires":[["1dcd59e7.77491e"]]},{"id":"9a43bf2b.42c99","type":"configNode","z":"","client_id":"xxxx","client_secret":"xxxxx","username":"xxxxx","password":"xxxxx!","device_id":"70:ee:50:3a:30:3c"},{"id":"2c54e5d1.9e495a","type":"mqtt-broker","z":"","name":"Teltonika","broker":"192.168.1.1","port":"1883","clientid":"NodeRed","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
You do not have the required permissions to view the files attached to this post.

Post Reply