Makerlife Weatherstation through MQTT

Moderator: leecollings

Post Reply
Empha88
Posts: 10
Joined: Sunday 28 April 2019 21:24
Target OS: -
Domoticz version:
Contact:

Makerlife Weatherstation through MQTT

Post by Empha88 »

Hi!

Im trying to get my Makerlife Weatherstation to work with Domoticz.
I have tried this script: https://github.com/kobbas/mqttweather
and a MQTT broker that is connected with Domoticz.
Then i added Dummy Hardware in Domoticz
But thats as far as i can get, how do i get the information from MQTT to the Dummy?
I have no experience with JSON and thats where im stuck i guess.
Or can i do this some other way?
SweetPants

Re: Makerlife Weatherstation through MQTT

Post by SweetPants »

You have to publish your messages to topic 'domoticz/in' and the idx in the JSON determines which dummy device will be updated. I'm not 100% sure if you can update every dummy device using MQTT. Have a look at: https://www.domoticz.com/wiki/MQTT
Empha88
Posts: 10
Joined: Sunday 28 April 2019 21:24
Target OS: -
Domoticz version:
Contact:

Re: Makerlife Weatherstation through MQTT

Post by Empha88 »

SweetPants wrote: Monday 29 April 2019 8:21 You have to publish your messages to topic 'domoticz/in' and the idx in the JSON determines which dummy device will be updated. I'm not 100% sure if you can update every dummy device using MQTT. Have a look at: https://www.domoticz.com/wiki/MQTT
How exactly do i do that? Could you describe for a dummie :)
SweetPants

Re: Makerlife Weatherstation through MQTT

Post by SweetPants »

Empha88 wrote: Monday 29 April 2019 9:15
SweetPants wrote: Monday 29 April 2019 8:21 You have to publish your messages to topic 'domoticz/in' and the idx in the JSON determines which dummy device will be updated. I'm not 100% sure if you can update every dummy device using MQTT. Have a look at: https://www.domoticz.com/wiki/MQTT
How exactly do i do that? Could you describe for a dummie :)
Did you take a look at the Wiki? It's all in there
Empha88
Posts: 10
Joined: Sunday 28 April 2019 21:24
Target OS: -
Domoticz version:
Contact:

Re: Makerlife Weatherstation through MQTT

Post by Empha88 »

SweetPants wrote: Monday 29 April 2019 10:00
Empha88 wrote: Monday 29 April 2019 9:15
SweetPants wrote: Monday 29 April 2019 8:21 You have to publish your messages to topic 'domoticz/in' and the idx in the JSON determines which dummy device will be updated. I'm not 100% sure if you can update every dummy device using MQTT. Have a look at: https://www.domoticz.com/wiki/MQTT
How exactly do i do that? Could you describe for a dummie :)
Did you take a look at the Wiki? It's all in there
Yes, Should i use NODE-Red to edit messages?
Empha88
Posts: 10
Joined: Sunday 28 April 2019 21:24
Target OS: -
Domoticz version:
Contact:

Re: Makerlife Weatherstation through MQTT

Post by Empha88 »

"2019-04-30 15:43:07.776 MQTT: Topic: domoticz/in, Message: {"temperature": 28.75, "rain": 0.2794, "windspeed": 0.6628257844249887}
2019-04-30 15:43:07.777 Error: MQTT: unknown idx received! (idx 0)"

This is what my log says right now, i change the "mqtt_c.publish('outside/weather/',payload)" to "mqtt_c.publish('domoticz/in',payload)
How do i connect the data to the right dummy device?
SweetPants

Re: Makerlife Weatherstation through MQTT

Post by SweetPants »

Empha88 wrote: Tuesday 30 April 2019 15:56 "2019-04-30 15:43:07.776 MQTT: Topic: domoticz/in, Message: {"temperature": 28.75, "rain": 0.2794, "windspeed": 0.6628257844249887}
2019-04-30 15:43:07.777 Error: MQTT: unknown idx received! (idx 0)"
I think you are missing the "idx":<idx> in your JSON string. Domoticz does not know now which device to update.
Something like this {"temperature": 28.75, "rain": 0.2794, "idx:" 123, "windspeed": 0.6628257844249887}
Empha88 wrote: Tuesday 30 April 2019 15:56 This is what my log says right now, i change the "mqtt_c.publish('outside/weather/',payload)" to "mqtt_c.publish('domoticz/in',payload)
How do i connect the data to the right dummy device?
use the idx from the dummy device in the above JSON. you can find it in the device list "Setup->Devices"

BTW, i am not sure if you did read the Wiki or understand it. The above JSON is not valid. Depending on the device_type, you should use nvalue or svalue to update a device like:
{
"command": "udevice",
"idx" : 7,
"nvalue" : 0,
"svalue" : "90;2975.00"
}
Empha88
Posts: 10
Joined: Sunday 28 April 2019 21:24
Target OS: -
Domoticz version:
Contact:

Re: Makerlife Weatherstation through MQTT

Post by Empha88 »

SweetPants wrote: Tuesday 30 April 2019 16:02
Empha88 wrote: Tuesday 30 April 2019 15:56 "2019-04-30 15:43:07.776 MQTT: Topic: domoticz/in, Message: {"temperature": 28.75, "rain": 0.2794, "windspeed": 0.6628257844249887}
2019-04-30 15:43:07.777 Error: MQTT: unknown idx received! (idx 0)"
I think you are missing the "idx":<idx> in your JSON string. Domoticz does not know now which device to update.
Something like this {"temperature": 28.75, "rain": 0.2794, "idx:" 123, "windspeed": 0.6628257844249887}
Empha88 wrote: Tuesday 30 April 2019 15:56 This is what my log says right now, i change the "mqtt_c.publish('outside/weather/',payload)" to "mqtt_c.publish('domoticz/in',payload)
How do i connect the data to the right dummy device?
use the idx from the dummy device in the above JSON. you can find it in the device list "Setup->Devices"

BTW, i am not sure if you did read the Wiki or understand it. The above JSON is not valid. Depending on the device_type, you should use nvalue or svalue to update a device like:
{
"command": "udevice",
"idx" : 7,
"nvalue" : 0,
"svalue" : "90;2975.00"
}
Thanks! Did what you said, then i get this:
"2019-04-30 16:14:44.418 MQTT: Topic: domoticz/in, Message: {"rain": 0.2794, "temperature": 27.875, "idx": 11, "windspeed": 0.4492980149457978}
2019-04-30 16:14:44.419 Error: MQTT: Invalid data received!"
Empha88
Posts: 10
Joined: Sunday 28 April 2019 21:24
Target OS: -
Domoticz version:
Contact:

Re: Makerlife Weatherstation through MQTT

Post by Empha88 »

"while True:
sleep (interval)
speed.append(wind(interval))
i += 1
if i == 15:
temper = temperature()
speed_avg = sum(speed,0.00)/len(speed)
payload=json.dumps({"rain":rain_cum,
"temperature":temper,
"windspeed":speed_avg,
"idx":11})
mqtt_c.publish('domoticz/in',payload)
# print('Publish data: ' + payload)
i=0
speed.clear()
else:
pass"
Guessing i have to change some names of the sensors to get it to work with the right dummy sensor.
Empha88
Posts: 10
Joined: Sunday 28 April 2019 21:24
Target OS: -
Domoticz version:
Contact:

Re: Makerlife Weatherstation through MQTT

Post by Empha88 »

"2019-04-30 17:29:45.464 MQTT: Topic: domoticz/in, Message: {"idx": 11, "svalue": "WB;WD;WS;WG;22;24", "command": "udevice", "nvalue": 0}"

So this is were im stuck right now, were do i put in the data i get from my windsensor?
tried putting the speed_avg everywhere wich is my data for the windsensor but ends up with error.
SweetPants

Re: Makerlife Weatherstation through MQTT

Post by SweetPants »

Empha88 wrote: Tuesday 30 April 2019 17:31 "2019-04-30 17:29:45.464 MQTT: Topic: domoticz/in, Message: {"idx": 11, "svalue": "WB;WD;WS;WG;22;24", "command": "udevice", "nvalue": 0}"

So this is were im stuck right now, were do i put in the data i get from my windsensor?
tried putting the speed_avg everywhere wich is my data for the windsensor but ends up with error.
Weather information is made of several different Dummy Sensors (multiple idx). There is no such thing as a single Weather device you can update. You have to create multiple devices and update accordingly (like the WIki Says). Different type of sensors have different update methodes.
Like for a Temp+Humidity device, the JSON is: '{"idx":184,"nvalue":0,"svalue":"20.2;50;2"}'
where:
20.2 = Temperature
50 = Humidity (percentage)
2 = Humidity Status (0=normal, 1=Comfortable, 2=Dry, 3=Wet)
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Makerlife Weatherstation through MQTT

Post by FireWizard »

Hi,

Reading this thread I don't think this way it is going to work.
However it is quite easy.
In general it is a bad idea to publish messages from external equipment directly into domoticz/in, because the syntax used by the external equipment will not match the syntax expected by Domoticz.
I assume, as I read it, this weather station will transmit a message every 5 minutes and it will look like {"temperature": 28.75, "rain": 0.2794, "windspeed": 0.6628257844249887}. As SweetPants already indicated Domoticz expects something else and it is dependent on the type of sensor.

As I see in the script the weather station gives you 3 sensors:
1. Temperature Sensor (°C)
2. Wind speed (m/s)
3. Rain (mm)

Although that you have the possibility of creating a combined sensor, I recommend to create one virtual sensor for each of the sensors of the weather station. So totally three sensors of the type, resp. Temperature, Wind and Rain. You can create a combined sensor for Wind+Temp+Chill, but in that case you have to calculate the chill. As said not recommended.

So first step is to create the MQTT hardware device.
MQTT Domoticz.png
MQTT Domoticz.png (134.46 KiB) Viewed 2483 times
If you have installed your MQTT broker on the same hardware device as Domoticz you may use "localhost", otherwise fill in the IP address of the broker.
For security reasons I recommend at least to use a username and password combination. You have to set this in your broker as well.
Domoticz will subscribe to domoticz/in and publish to domoticz/out.

I assume that your MQTT broker (Mosquitto?) is properly installed.
If so you should see a lot of messages published to domoticz/out if you connect to the broker with a suitable client.
One I can recommend is MQTTfx (https://mqttfx.jensd.de).

The next step you should do is to reverse all the changes you have made in the weather.py file.
Or if you are not sure what has been changed re-install it.
The only thing you should modify in that file weather.py is the following:

1. Line 15: Your username and Your password (if you have set a username/password in your broker!)
2. Line 16: Your IP address (or localhost if the broker and the python script runs on the same hardware)
Do NOT change the phrase outside/weather, anywhere in the file.

If you run the script as indicated in the readme file you should be able to subscribe with e.g. MQTTfx to the topic outside/weather.
If everything is alright you will receive something like {"temperature": 28.75, "rain": 0.2794, "windspeed": 0.6628257844249887}

However as Sweetpants also said Domoticz expects another syntax for the sensors.
See: https://www.domoticz.com/wiki/Domoticz_ ... emperature

The following syntax is required:

For the Temperature Sensor:

Temperature:

/json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=TEMP

IDX = id of your device (This number can be found in the devices tab in the column "IDX")
TEMP = Temperature

For the Wind Speed sensor:

Wind

/json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=WB;WD;WS;WG;22;24

IDX = id of your device (This number can be found in the devices tab in the column "IDX")
WB = Wind bearing (0-359)
WD = Wind direction (S, SW, NNW, etc.)
WS = 10 * Wind speed [m/s]
WG = 10 * Gust [m/s]
22 = Temperature
24 = Temperature Windchill

For the Rain Sensor:

Rain

/json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=RAINRATE;RAINCOUNTER

IDX = id of your device (This number can be found in the devices tab in the column "IDX")
RAINRATE = amount of rain in last hour in [mm x 100]
RAINCOUNTER = continues counter of fallen Rain in [mm]

As an example if you want to send the temperature from the MQTT broker to Domoticz use the following JSON commands:
{
"command": "udevice",
"idx" : 7,
"nvalue" : 0,
"svalue" : "28,75"
}

If you don't have a value insert 0 (zero), otherwise your database may get corrupted.

So you have to convert your payload (message) from the weather station to something above that Domoticz recognizes.
To do that, you have 2 options:

1. If you are a programmer then you can use a scripting language, like LUA, dzVents, Python or PHP or whatever.
2. If you don't feel comfortable in those scripting languages, use Node-Red, as already suggested.

With Node-Red such a conversion is more or less straight forward.
If you don't have NodeJS and Node-Red already installed, install it with the following instructions:
NodeJS: https://www.instructables.com/id/Instal ... pberry-Pi/
Node-RED: https://nodered.org/docs/getting-started/installation

If you need further support with the conversion in Node-Red don't hesitate to ask, but publish your results so far.
Last edited by FireWizard on Saturday 04 May 2019 22:25, edited 2 times in total.
Empha88
Posts: 10
Joined: Sunday 28 April 2019 21:24
Target OS: -
Domoticz version:
Contact:

Re: Makerlife Weatherstation through MQTT

Post by Empha88 »

FireWizard wrote: Wednesday 01 May 2019 18:18 Hi,

Reading this thread I don't think this way it is going to work.
However it is quite easy.
In general it is a bad idea to publish messages from external equipment directly into domoticz/in, because the syntax used by the external equipment will not match the syntax expected by Domoticz.
I assume, as I read it, this weather station will transmit a message every 5 minutes and it will look like {"temperature": 28.75, "rain": 0.2794, "windspeed": 0.6628257844249887}. As SweetPants already indicated Domoticz expects something else and it is dependent on the type of sensor.

As I see in the script the weather station gives you 3 sensors:
1. Temperature Sensor (°C)
2. Wind speed (m/s)
3. Rain (mm)

Although that you have the possibility of creating a combined sensor, I recommend to create one virtual sensor for each of the sensors of the weather station. So totally three sensors of the type, resp. Temperature, Wind and Rain. You can create a combined sensor for Wind+Temp+Chill, but in that case you have to calculate the chill. As said not recommended.

So first step is to create the MQTT hardware device.

MQTT Domoticz.png

If you have installed your MQTT broker on the same hardware device as Domoticz you may use "localhost", otherwise fill in the IP address of the broker.
For security reasons I recommend at least to use a username and password combination. You have to set this in your broker as well.
Domoticz will subscribe to domoticz/in and publish to domoticz/out.

I assume that you MQTT broker (Mosquitto?) is properly installed.
If so you should see a lot of messages published to domoticz/out if you connect to the broker with a suitable client.
One I can recommend is MQTTfx (https://mqttfx.jensd.de).

The next step you should do is to reverse all the changes you have made in the weather.py file.
Or if you are not sure what has been changed re-install it.
The only thing you should modify in that file weather.py is the following:

1. Line 15: Your username and Your password (if you have set a username/password in your broker!)
2. Line 16: Your IP address (or localhost if the broker and the python script runs on the same hardware)
Do NOT change the phrase outside/weather, anywhere in the file.

If you run the script as indicated in the readme file you should be able to subscribe with e.g. MQTTfx to the topic outside/weather.
If everything is alright you will receive something like {"temperature": 28.75, "rain": 0.2794, "windspeed": 0.6628257844249887}

However as Sweetpant also said Domoticz expects another syntax for the sensors.
See: https://www.domoticz.com/wiki/Domoticz_ ... emperature

The following syntax is required:

For the Temperature Sensor:

Temperature:

/json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=TEMP

IDX = id of your device (This number can be found in the devices tab in the column "IDX")
TEMP = Temperature

For the Wind Speed sensor:

Wind

/json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=WB;WD;WS;WG;22;24

IDX = id of your device (This number can be found in the devices tab in the column "IDX")
WB = Wind bearing (0-359)
WD = Wind direction (S, SW, NNW, etc.)
WS = 10 * Wind speed [m/s]
WG = 10 * Gust [m/s]
22 = Temperature
24 = Temperature Windchill

For the Rain Sensor:

Rain

/json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=RAINRATE;RAINCOUNTER

IDX = id of your device (This number can be found in the devices tab in the column "IDX")
RAINRATE = amount of rain in last hour in [mm x 100]
RAINCOUNTER = continues counter of fallen Rain in [mm]

As an example if you want to send the temperature from the MQTT broker to Domoticz use the following JSON commands:
{
"command": "udevice",
"idx" : 7,
"nvalue" : 0,
"svalue" : "28,75"
}

If you don't have a value insert 0 (zero), otherwise your database may get corrupted.

So you have to convert your payload (message) from the weather station to something above that Domoticz recognizes.
To do that, you have 2 options:

1. If you are a programmer then you can use a scripting language, like LUA, dzVents, Python or PHP or whatever.
2. If you don't feel comfortable in those scripting languages, use Node-Red, as already suggested.

With Node-Red such a conversion is more or less straight forward.
If you don't have NodeJS and Node-Red already installed, install it with the following instructions:
NodeJS: https://www.instructables.com/id/Instal ... pberry-Pi/
Node-RED: https://nodered.org/docs/getting-started/installation

If you need further support with the conversion in Node-Red don't hesitate to ask, but publish your results so far.
Oh, this is just what i need, gonna try it this weekend, will come back with the results, BIG thank you!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest