axlan / sainlogic-sdr

Project to reverse engineer Sainlogic weather station wireless data and provide GNU Radio reciever
8 stars 4 forks source link

ESP Decoding #1

Closed Joeee83 closed 3 years ago

Joeee83 commented 3 years ago

Hi, i want to connect my Sainlogic 0835 to my home assistant. This is easy possible by using mqtt. Could you please add the decoding code to the esp8266, so that den mqtt server gets useable / user readable data from the esp? I have also a thread with rflink - but got no response. Unfortionatly i can't program this good. TIA, Joe

axlan commented 3 years ago

Hi Joe,

The basic idea is easy enough (take the logic in https://github.com/axlan/sainlogic-sdr/tree/main/client and add it as a new topic in the firmware), but there's a few complications:

  1. How to wrap these values into an MQTT topic. I'm less familiar with how the data is expected to be packaged for home assistant interfaces, I assume that the interface you're interested in expects the data to be received as a JSON string?
  2. What units to use. The sensor outputs the measurements in a mix of mostly metric, with Fahrenheit, which is what I'd use, but might not be what you'd want. You could add MQTT subscriptions for setting the desired units or add JSON keys for each unit, but that could balloon the complexity.
  3. The rain measurement is stateful. The sensor reports the amount of rain since it was reset. The display keeps track of this to report the hourly/daily/total rainfall. This eventually rolls over. This can be tracked similarly in the ESP8266 (my python code converts it to rain over the last hour), but it also adds some complexity.

I might take a stab at doing the simplest form of this (converting the values, creating a single new unsolicited published topic, adding the default units, not worrying about rain measurement state), which hopefully helps you out with your use case.

Joeee83 commented 3 years ago

Hi axlan, thanks for getting back to me.

1. How to wrap these values into an MQTT topic. I'm less familiar with how the data is expected to be packaged for home assistant interfaces, I assume that the interface you're interested in expects the data to be received as a JSON string?

I see two options for this:

2. What units to use. The sensor outputs the measurements in a mix of mostly metric, with Fahrenheit, which is what I'd use, but might not be what you'd want. You could add MQTT subscriptions for setting the desired units or add JSON keys for each unit, but that could balloon the complexity.

I would go with the metric system, as i live in a country that uses it. Loocking from the software point of view, i can see no sense in converting it forth and back..

3. The rain measurement is stateful. The sensor reports the amount of rain since it was reset. The display keeps track of this to report the hourly/daily/total rainfall. This eventually rolls over. This can be tracked similarly in the ESP8266 (my python code converts it to rain over the last hour), but it also adds some complexity.

I would be fine with the growing value too, as i would see this as a seperate step to the weather station. Homeassisant can't work with rainfall out of the box with its weather template but it could perhaps with a history graph. Eventually it would be a good idea to be able to reset the value in the esp to 0 per mqtt command (use the current value as an offset). Like that the controller could keep track of the time and if the value turns over it just messes up one time intervall in the log.

I might take a stab at doing the simplest form of this (converting the values, creating a single new unsolicited published topic, adding the default units, not worrying about rain measurement state), which hopefully helps you out with your use case.

That would be absolutly great!

axlan commented 3 years ago

OK, just pushed an update to the ESP8266 firmware. It adds a new topic weather_decoded . An example of the JSON it publishes looks like:

{"temp_f": 59.90, "humidity_%": 94.00, "wind_dir_deg": 169.00, "avr_wind_m/s": 0.00, "gust_wind_m/s": 0.30, "rain_mm": 12.30}