Get sensor values with MQTT into Domoticz [Solved]

Everything about esp8266 and more.

Moderator: leecollings

User avatar
FireWizard
Posts: 1766
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Get sensor values with MQTT into Domoticz

Post by FireWizard »

Hi McMellow,

This is wonderfull
But does this mean that you brew your own beer?

If I see this screenshot, I think I am able to make a code for the function node.
You can delete your JSON node. We don't need it.

I assume that it is ok to have the four messages.
Did you already prepare your sensors?

Regards
User avatar
FireWizard
Posts: 1766
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Get sensor values with MQTT into Domoticz

Post by FireWizard »

Hello McMellow,

Please find below the new contents for the function node.
Your screenshot clarified everything and it was much simpler as I thought.

Your flow should look as follows:

Screenshot_ispindel-flow.png
Screenshot_ispindel-flow.png (11.54 KiB) Viewed 3958 times

The result should be as follows:

Screenshot_ispindel-result.png
Screenshot_ispindel-result.png (8.84 KiB) Viewed 3958 times

This is an example of the tilt. You should see 4 results (tilt, temperature, battery and gravity)

Insert the following code in your function node.
Replace the number after idx:1001,1002,1003,1004 with the idx numbers of your sensors.
Check first, that the output matches exactly with the screenshot of the result, before you connect the output of the "Function" node with the input of the MQTT node (Domoticz in)

Code: Select all

switch (msg.topic) {

    case "ispindel/ispindel01/tilt":
    msg.payload = {"command":"udevice","idx":1001,"nvalue":0,"svalue":msg.payload};
    break;

    case "ispindel/ispindel01/temperature":
    msg.payload = {"command":"udevice","idx":1002,"nvalue":0,"svalue":msg.payload};
    break;

    case "ispindel/ispindel01/battery":
    msg.payload = {"command":"udevice","idx":1003,"nvalue":0,"svalue":msg.payload};   
    break;

    case "ispindel/ispindel01/gravity":
    msg.payload = {"command":"udevice","idx":1004,"nvalue":0,"svalue":msg.payload};
    break;
}
return msg;
It should function now.

Best Regards
User avatar
McMelloW
Posts: 430
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Get sensor values with MQTT into Domoticz

Post by McMelloW »

FireWizard wrote: Wednesday 25 December 2019 18:56 Hi McMellow,

This is wonderful
But does this mean that you brew your own beer?
4
Yes indeed, I am a hobby homebrewer. The iSpindel can connect to ubidots.com, but I don't want to be depended on a third party. That is why I like to make use of Domoticz
If I see this screenshot, I think I am able to make a code for the function node.
You can delete your JSON node. We don't need it.
That is done already.
I assume that it is ok to have the four messages.
Did you already prepare your sensors?
Yes, just these messages. But I see it is just copy and paste and a few alterations per message.

Thanks a lot. I will keep you updated
Greetings McMelloW
User avatar
McMelloW
Posts: 430
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Get sensor values with MQTT into Domoticz

Post by McMelloW »

FireWizard wrote: Wednesday 25 December 2019 19:47 Hello McMellow,

Please find below the new contents for the function node.
Your screenshot clarified everything and it was much simpler as I thought.
Thank you so much, changed the flow to your example. Filled the function with your code and this is a part of the output.
Debug_Domoticz_Func.png
Debug_Domoticz_Func.png (8.59 KiB) Viewed 3953 times

Connect it to the node Domoticz In and see what happens with the devices in Domoticz.
And ofcourse, I have to understand the How and Why of it all.
Greetings McMelloW
User avatar
McMelloW
Posts: 430
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Get sensor values with MQTT into Domoticz

Post by McMelloW »

Hi FireWizard.

Thank you very much for all your support.
iSpindel Dashboard.png
iSpindel Dashboard.png (25.61 KiB) Viewed 3952 times
The final result in Domoticz
Greetings McMelloW
User avatar
FireWizard
Posts: 1766
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Get sensor values with MQTT into Domoticz

Post by FireWizard »

Hello McMellow,

Always nice to see such a screenshot and all the sensors working. I hope your beer is even getting better now ;) .
I see you use a nice collection with icons as well

Just 1 comment for the cosmetics.
In the temperature sensor you indicate 20.62o C. You should move the space between the number and o, so that you will see 20.62 oC.

In the sensor "Gravity iSpindel the number 891.515 has no unit. I wondered what it is.
Is it gal from Galileo, also cm/s2? See: https://en.wikipedia.org/wiki/Standard_gravity
Now the How and Why.

Your iSpindel device publishes a very nice, but simple JSON output. What it is, is enclosed in the topic e.g. ispindel/ispindel01/tilt.
The payload is simple the value, related to that topic. Therefore you have as many publications, as there is data.
Of course Node Red can combine these, but that makes no sense for our purpose. It is also the reason that the JSON node does nothing.
But it is also the reason that the Javascript code in the Function node is so simple and just a matter of copy/paste

The function itself is an efficient replacement of "if.... then". See: https://www.w3schools.com/js/js_switch.asp
You even can omit the last break, but in case of copy/paste , I leave it mostly there.

The way you publish data to Domoticz depends on the sensor. It varies somewhat. So it is important to know which sensor you want to control.
You will find a lot of information at:

https://www.domoticz.com/wiki/MQTT
https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s

But I use mostly this one: https://piandmore.wordpress.com/2019/02 ... -domoticz/

Something to read these days. :)

Take a beer en best regards.
User avatar
McMelloW
Posts: 430
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Get sensor values with MQTT into Domoticz

Post by McMelloW »

FireWizard wrote: Wednesday 25 December 2019 22:19 Always nice to see such a screenshot and all the sensors working. I hope your beer is even getting better now ;) .
I see you use a nice collection with icons as well

Just 1 comment for the cosmetics.
In the temperature sensor you indicate 20.62o C. You should move the space between the number and o, so that you will see 20.62 oC.
The temperature sensor is a default sensor. You can not change the ° C Unless you know where to be under the domoticz hood
The other sensors are customer sensors

Thanks for all the links. Sure I will dig into this.

Next step is a live graphical cart for the fermentation period up to 4-5 weeks Something like this
Image

BTW. We are almost neighbors. Harderwijk - Voorthuizen
Greetings McMelloW
User avatar
FireWizard
Posts: 1766
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Get sensor values with MQTT into Domoticz

Post by FireWizard »

Hi McMelloW,

Regarding the temperature in oC, I see it now. Some cosmetics.
All temperature sensors have the same.

Nice graphics.

And yes, we are living not that far away.

Regards
User avatar
McMelloW
Posts: 430
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Get sensor values with MQTT into Domoticz

Post by McMelloW »

FireWizard wrote: Wednesday 25 December 2019 22:19 Hello McMellow,

Always nice to see such a screenshot and all the sensors working. I hope your beer is even getting better now ;) .
I see you use a nice collection with icons as well
See this link where you can create your own icons for Domoticz
FireWizard wrote: Thursday 26 December 2019 12:03 Regarding the temperature in oC, I see it now. Some cosmetics.
All temperature sensors have the same.
We can open an issue to get it done. :D
Greetings McMelloW
User avatar
FireWizard
Posts: 1766
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Get sensor values with MQTT into Domoticz

Post by FireWizard »

@McMelloW

Thank you for the link, however I had seen it before.
So far I created my icons manually, but will try this once.

I think we leave it so far here,. or make a pull request on github.

Have a nice day

Regards
Attie
Posts: 5
Joined: Tuesday 02 May 2017 21:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by Attie »

Hello,

Is it possible to create a WiKi for this, to make other brewers with an iSpindel happy?
This is higer level Domoticz and i love to use my iSpindel in combination with Domoticz!

Regards
User avatar
McMelloW
Posts: 430
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by McMelloW »

Many thanks to FireWizard for all his help in getting the data from my MQTT-broker via Node Red into domoticz
But, working with the iSpindel data within Domoticz was not very easy and handy.

Finally, I found this solution on the german hobbybrauer.de forum. There is a topic on the local TCP-server and on build and use of the iSpindel
Installed the TCP-Server on my RPi and this is working very nice next to domoticz. When I don't use the iSpindel, the server can be stopped total independently from Domoticz.
Last edited by McMelloW on Wednesday 29 January 2020 10:49, edited 1 time in total.
Greetings McMelloW
User avatar
FireWizard
Posts: 1766
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by FireWizard »

Hello all,

Attie wrote:
Is it possible to create a WiKi for this, to make other brewers with an iSpindel happy?
This is higer level Domoticz and i love to use my iSpindel in combination with Domoticz!
Yes, of course it is always possible to create a WiKi or a Howto.

It is not higher level Domoticz.
We have many devices in the IoT world, that uses the MQTT protocol.

You can think of all kind of small devices, like the iSpindel, but I even connected my (Volvo) car with MQTT to Domoticz.

Basicaly it is in Domoticz only 2 steps:
1. Install MQTT hardware
2. Create a (number of) virtual sensors.

The rest is Node Red, which "translates" the received input to something Domoticz can understand. The received input is almost always different.
For MQTT and Domoticz we have a WiKi, https://www.domoticz.com/wiki/MQTT

For the installation of NodeJS, Node Red and Mosquitto, several guidelines are available on the Internet. So a WiKi on this part would probably be "another copy of the same"

Regarding the iSpindel, it is probably better to look @McMelloW solution, as Domoticz is obviously less suitable for it.

Regards
accel
Posts: 4
Joined: Wednesday 28 October 2015 16:44
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Netherlands
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by accel »

Hello all,

I like connect my solar charge controller to Domoticz and I need some help with what I should put in the fuction node of
Node Red.
The solar charge controller is connected to my mosquitto broker and when I subscribe to the solar/# topic via SSH get this:

Code: Select all

mosquitto_sub -h 192.168.1.111 -v -t solar/#

solar {"t":1597241342,"pv.v":83.72,"pv.c":5.9,"pv.p":494.57,"bt.v":26.58,"bt.c":18.48,"bt.t":39.05}
I already made 6 dummy switches in Domoticz for the 6 MQTT sensors.
t is for time (and is not important for now)
pv.v stands for the solar panels Voltage in V
pv.c stands for the solar panels Current in A
pv.p stands for the solar panels Power in W
bt.v stands for the batterybank Voltage in V
bt.c stands for the batterybank Current in A
bt.t stands for the batterybank Temp in C

How can I send the induvidual values to domoticz/in?

Thanks a lot for your help. I am struggling with this for awhile now and I hope you can help me!
User avatar
FireWizard
Posts: 1766
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by FireWizard »

@accel

Hi,

Please find a working flow below.

Do not forget to change the idx numbers in the "Function Node" to the one you need.
I assumed that for the Watt, you have created a sensor of the type "Usage" and not "Electric"

Test it and let me know.

Code: Select all

[{"id":"12605f32.f6bed9","type":"mqtt in","z":"792e4e88.8fa0f","name":"","topic":"solar","qos":"2","datatype":"json","broker":"28f2a34.5e04cdc","x":200,"y":280,"wires":[["f2878238.eca2b8"]]},{"id":"f2878238.eca2b8","type":"function","z":"792e4e88.8fa0f","name":"","func":"var msg1 = {}; // pv.v stands for the solar panels Voltage in V\nvar msg2 = {}; // pv.c stands for the solar panels Current in A\nvar msg3 = {}; // pv.p stands for the solar panels Power in W\nvar msg4 = {}; // bt.v stands for the batterybank Voltage in V\nvar msg5 = {}; // bt.c stands for the batterybank Current in A\nvar msg6 = {}; // bt.t stands for the batterybank Temp in C\n\nmsg1.payload = {\"command\":\"udevice\",\"idx\":1001,\"svalue\":msg.payload[\"pv.v\"].toString()};\nmsg2.payload = {\"command\":\"udevice\",\"idx\":1002,\"svalue\":msg.payload[\"pv.c\"].toString()};\nmsg3.payload = {\"command\":\"udevice\",\"idx\":1003,\"svalue\":msg.payload[\"pv.p\"].toString()};\nmsg4.payload = {\"command\":\"udevice\",\"idx\":1004,\"svalue\":msg.payload[\"bt.v\"].toString()};\nmsg5.payload = {\"command\":\"udevice\",\"idx\":1005,\"svalue\":msg.payload[\"bt.c\"].toString()};\nmsg6.payload = {\"command\":\"udevice\",\"idx\":1006,\"svalue\":msg.payload[\"bt.t\"].toString()};\n\nreturn [[msg1,msg2,msg3,msg4,msg5,msg6]];","outputs":1,"noerr":0,"initialize":"","finalize":"","x":380,"y":280,"wires":[["9f6e86dc.b972c8","cf1e2ab5.bc483"]]},{"id":"cf1e2ab5.bc483","type":"mqtt out","z":"792e4e88.8fa0f","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"28f2a34.5e04cdc","x":590,"y":280,"wires":[]},{"id":"9f6e86dc.b972c8","type":"debug","z":"792e4e88.8fa0f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":340,"wires":[]},{"id":"28f2a34.5e04cdc","type":"mqtt-broker","z":"","name":"Domoticz","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

Regards
accel
Posts: 4
Joined: Wednesday 28 October 2015 16:44
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Netherlands
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by accel »

@FireWizard

It is working!! Finally it is working!! Thanks man. Because the dot in the valuename I couldn't get the earlier example to work.
And I am not a Javascript wizard like you are ;) Image
Jones69
Posts: 1
Joined: Thursday 04 June 2020 22:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by Jones69 »

Hi,

I`m a newbe with domotics and deffenetly with iSpindel. It is great work by accel and McMellW and I should build up similar system. I’m brewing apple sider in several tanks and annual volume Is 700-1500 l.

Did you get data strait from iSpindel to Domiticz using MQTT protocol and ip of Domiticz server? Or are you using a MQTT server between.

Is it possible for you to write simple wiki step-by-step help for us newbies?
Stiv32
Posts: 10
Joined: Sunday 08 September 2019 7:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by Stiv32 »

Good morning, I need a little help with the function to post a topic like this to Domoticz

Client mosq-uywU4RYJfvohos10ic received PUBLISH (d0, q0, r0, m0, 'energy/growatt', ... (372 bytes))
{"device": "6FZI9080D7", "time": "2020-10-13T16:34:57", "buffered": "no", "values": {"pvstatus": 0, "pv1watt": 0, "pv2watt": 0, "pvpowerin": 0, "pvpowerout": 0, "pvfrequentie": 4999, "pvgridvoltage": 2432, "pvenergytoday": 12, "pvenergytotal": 42099, "pv1voltage": 2031, "pv2voltage": 2027, "pv1current": 0, "pv2current": 0, "pvtemperature": 130, "pvipmtemperature": 222}}
User avatar
FireWizard
Posts: 1766
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by FireWizard »

Hi @Stiv32

The values published under the topic (obviously) energy/growatt can be send to Domoticz through Node Red.
Node Red for Raspberry Pi can be installed following the guideline at: https://nodered.org/docs/getting-started/raspberrypi

It will produce the following data:

Screenshot_growatt.png
Screenshot_growatt.png (21.83 KiB) Viewed 3086 times

Can you indicate which of the values (under values) you want to send to Domoticz. The Units are important.
I see, some of the values has to be divided, like pvfrequentie (by 100) or the voltage (by 10).
The temperature, is it degrees Celsius or Fahrenheit? Do I have to divide the values?

On the other hand for Domoticz exists a Python plug-in. Isn't that a solution?

Regards
Stiv32
Posts: 10
Joined: Sunday 08 September 2019 7:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by Stiv32 »

Thank you for your response. The current solution lacks values that are important to me - such as grid voltage and inverter temperature. The temperature is in Celsius and unfortunately you have to divide the values
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests