Domoticz weather prediction: Unknown

by Chief
Temp + Hum + Baro virtual sensor

This is a Temp+Hum+Baro virtual sensor in Domoticz, or to clarify it is its graphical representation. It sure looks nice but there is one very annoying thing going on here and that would be “Prediction: Unknown”. Later we will deal with this problem after we explain our setup and what is going on in the background.

Environment

In this case, I have Domoticz running on my Windows 10 PC with (yes it is not on Raspberry Pi, can you imagine 🙂 ) I have PC running all the time anyway so that is the main reason for Domoticz on PC and regarding that subject, we will stop right now. On the other side is ESP8266 with the Tasmota firmware and Bosch BME280 sensor. For easier understanding we will call ESP and BME together “physical sensor”, and another side that represents and logs data on Domoticz will be called “virtual sensor”.

This “Prediction: Unknown” message is not a big deal, but since the rest of the sensor looks so nice it is a shame not to get it in a perfect state. Therefore, I started with the assumption (and we all know that assumption is the mother of all fuckups) that physical sensor is just feeding the virtual sensor and Domoticz with data and that “Weather prediction” is done on Domoticz by applying some kind of algorithm to gathered pressure data. WRONG!

How it really works

I looked into the DeviceStatus table of the Domoticz DB and under sValue for my device, I found data like this: 3.2;66.3;1;1019.5;5. There are five values in sValue: 3.2 was the temperature at the moment, 66.3 was the humidity, 1 was for “Feels like” , 1019.5 was for pressure, and 5 was value for “Weather forecast”. I Googled a little bit and here is what I found regarding Forecast mapping in Domotiz.

Forecast:
0 – Stable
1 – Clear/Sunny
2 – Cloudy/Rain
3 – Not stable
4 – Thunderstorm
5 – Unknown

“Unknown” explained my problem, but beware, this is not correct mapping. On the other hand, this is the correct one:

0 – No Info
1 – Sunny
2 – Partly Cloudy
3 – Cloudy
4 – Rain
5 – Unknown

Therefore, take care as there is lot of semi truth out there….

As a result, it was logical to see what kind of data is Tasmota sending to Domoticsz so I looked into a Domoticz log, and this was coming: MQTT: Topic: domoticz/in, Message: {“idx”:148,”nvalue”:0,”svalue”:”3.2;66.3;1;1019.5;5″,”Battery”:100,”RSSI”:5} So it matched values in DB, that was concluded, weather forecast data should come from the source. And Tasmota was sending 5, and 5 means unknown. But what to do now?

Solution

This matter made me stuck for a few days in a discussion with my colleagues. We were trying to figure out possible solutions. A friend sent me the link to a Domoticz forum where guys published Script To Parse WeatherUnderground Multi-Value Sensor, and that was our base. The script can be found at this address https://www.domoticz.com/forum/viewtopic.php?t=3830&start=40 along with some other interesting thoughts.

After that we created device lua script with this code:

  -- + lua / device script
local sensorx = 'ESP Outside' --name of the sensor that  has a problem with weather prediction (Temp+Hum+Baro virtual sensor), you put your sensor name
commandArray = {}

if (devicechanged[sensorx]) then
    
        WeatherTemp, WeatherHumidity, HumFeelsLike, WeatherPressure, WeatherPressureForecast = otherdevices_svalues[sensorx]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
       WeatherTemp = tonumber(WeatherTemp)
      WeatherHumidity = tonumber(WeatherHumidity)
       HumFeelsLike = tonumber(HumFeelsLike)
        WeatherPressure = tonumber(WeatherPressure) -- hPa
       WeatherPressureForecast = tonumber(WeatherPressureForecast)
         
         if (WeatherPressure == 0) then
             WeatherPressureForecast = 0
                        elseif (WeatherPressure > 1030) then
          WeatherPressureForecast = 1
        elseif ((WeatherPressure > 1010) and (WeatherPressure <= 1030)) then
        WeatherPressureForecast = 2
      elseif ((WeatherPressure > 990) and (WeatherPressure <= 1010)) then
       WeatherPressureForecast = 3
     elseif ((WeatherPressure > 970) and (WeatherPressure <= 990)) then
     WeatherPressureForecast = 4
 end
 
    --[[
    Forecast:

0 - No Info
1 - Sunny
2 - Partly Cloudy
3 - Cloudy
4 - Rain
5 - Unknown
    --]]
 commandArray['UpdateDevice'] = '148|0|' .. WeatherTemp ..';'.. WeatherHumidity ..';'.. HumFeelsLike ..';' .. WeatherPressure.. ';'.. WeatherPressureForecast
 -- 148 is the idx of a virtual sensor that is going to be fixed, in this case it is the idx of the "ESP Outside" virtual sensor. You put your idx number

 end
return commandArray

Comments are already in the code, therefore you should not have any problems adjusting it for your sensors and environment. Above all, do not create Lua / All (commented) script, but Lua/Device script. It may work anyway but as a result, you will have an error in Domoticz log file. I hope this will save you some time 🙂 . The script was up and running after this. I peeked in DB to see, what is going on, and there was “3” smiling out on me from the end of the sValue data. 🙂

ESP8266
ESP8266 + BME280 + Tasmota received data in Domoticz DB

What the script does

We dealt with this problem this way. It can be dealt with in many other ways. The script basically reads all the values from the virtual sensor. Then it puts them in variables. After that, it does some math (comparing may be a more modest word) with pressure and as a result updates, four values of the virtual sensor with the same values and the fifth data field is updated with the number that is calculated based on the pressure. I borrowed that calculation from this article:https://diyprojects.io/esp8266-web-client-sending-data-domoticz-tcp-ip-wireless-api-json/#.Xix9UshKiUl Article is great, therefore if you like this stuff I recommend it for reading. The script runs every time the virtual sensor gets an update from the Tasmota, and in my case, it is every 5 minutes, in other words, it is not putting any heavy load on the hardware.

I`m not gonna enter into weather prediction algorithm, that is not a subject of this article. This is not a commercial weather station or piece of scientific equipment, it is a homemade system and should be treated like that. On the other hand it should work at least like it supposed to. That was the point.

Result

Domoticz virtual sensor

So if you liked this article may be the one about micro-controllers would be also an interesting one, so if you have some time take a look here. And in the end, thank dr_Kosh for the great contribution regarding this problem.

Once again, thank you for reading,

🙂

Related Posts

Leave a Comment

It`s all about Technology