Wheather forecasts output compatible with android-mqtt-alarm-panel (SOLVED)

Dear all,

I’m using the Android MQTT Alarm Panel to manage my Alarmo system. Recent changes in the weather forecast output have produced a format that is not compatible with the previous version. Is there a way to produce an output compatible with the requested format as described here MQTT Weather ?
Thanks you

For those situations where integrations still rely on the old forecast model, and frankly because I have a lot of things that I wrote internally that use that model, you can build a sensor where you simply build your own forecast attribute. The only issue will be if they are locking it down specific to the weather domain or if you can use any sensor, since even template weather entities won’t accept forecast as an attribute any longer.

The way I do it is to create a trigger sensor that runs on HA startup and then every 5 minutes to populate an attribute called “forecast” from the “get_forecasts” service call.

Can you provide me some examples ?

I almost did but before I fix up my code to be suitable for your need you might want to make sure your integration doesn’t require it to be a weather domain.

Please explain further: make sure your integration doesn’t require it to be a weather domain. You can find a demo of the required output in the link I provided earlier.

From what I can see it does not rely on a weather entity, but if you are not quite sure how to have verified that then changing your MQTT payload may be difficult for you as well.

Do you need daily or hourly for this? I don’t use MQTT in this way nor do I use that integration but if you only need a sensor for the forecast then it’s not difficult to do once you let me know which you need.

dear @CO_4X4
This is the actual output of calling the getweather.forecasts service on a daily basis:

    - condition: partlycloudy
      datetime: "2024-05-24T10:00:00+00:00"
      wind_bearing: 305.3
      temperature: 24.2
      templow: 12.8
      wind_speed: 16.6
      precipitation: 0
      humidity: 49
    - condition: cloudy
      datetime: "2024-05-25T10:00:00+00:00"
      wind_bearing: 259.2
      temperature: 20.9
      templow: 13.6
      wind_speed: 15.5
      precipitation: 0.5
      humidity: 59
    - condition: sunny
      datetime: "2024-05-26T10:00:00+00:00"
      wind_bearing: 329.5
      temperature: 25
      templow: 13.3
      wind_speed: 23.4
      precipitation: 0
      humidity: 51
    - condition: cloudy
      datetime: "2024-05-27T10:00:00+00:00"
      wind_bearing: 252.2
      temperature: 25.5
      templow: 15.3
      wind_speed: 10.8
      precipitation: 0.3
      humidity: 50
    - condition: sunny
      datetime: "2024-05-28T10:00:00+00:00"
      wind_bearing: 217.2
      temperature: 24.2
      templow: 15.2
      wind_speed: 14
      precipitation: 1.1
      humidity: 49
    - condition: rainy
      datetime: "2024-05-29T10:00:00+00:00"
      wind_bearing: 278.8
      temperature: 23.4
      templow: 16.2
      wind_speed: 15.1
      precipitation: 2.7
      humidity: 57

And this is an example of the output to publish via MQTT:

{''weather'':{''condition'':''sunny'',''humidity'':61,''temperature'':27.2,''forecast'':[{'condition': 'sunny', 'temperature': 19.8, 'templow': 13.5, 'datetime': '2020-11-30T15:00:00+00:00', 'wind_bearing': 101.4, 'wind_speed': 30.6}, {'condition': 'cloudy', 'precipitation': 1.2, 'temperature': 23.0, 'templow': 16.8, 'datetime': '2020-12-01T15:00:00+00:00', 'wind_bearing': 17.1, 'wind_speed': 24.5}, {'condition': 'partlycloudy', 'temperature': 26.0, 'templow': 20.5, 'datetime': '2020-12-02T15:00:00+00:00', 'wind_bearing': 48.8, 'wind_speed': 14.0}, {'condition': 'partlycloudy', 'precipitation': 0.3, 'temperature': 25.2, 'templow': 19.7, 'datetime': '2020-12-03T15:00:00+00:00', 'wind_bearing': 71.5, 'wind_speed': 22.7}, {'condition': 'partlycloudy', 'temperature': 22.7, 'templow': 18.0, 'datetime': '2020-12-04T15:00:00+00:00', 'wind_bearing': 105.5, 'wind_speed': 33.5}]}}

Is this enough for you to write a template?
Thank you :pensive:

for further reference, I solved the problem by writing two triggers. One that populate a sensor with the information of weather.get_forecasts acquired on an hourly basis and one on daily basis:

- trigger:
    - platform: time_pattern
#      hours: '*'
#      minutes: '*'
      seconds: "/10"
    - service: weather.get_forecasts
        type: hourly
        entity_id: weather.forecast_home
      response_variable: hourly
    - name: Weather Forecast Hourly
      unique_id: weather_forecast_hourly
      state: "{{ now().isoformat() }}"
        forecast: "{{ hourly['weather.forecast_home'].forecast }}"
- trigger:
    - platform: time_pattern
      hours: /1
      minutes: '*'
      seconds: '*'
    - service: weather.get_forecasts
        type: daily
        entity_id: weather.forecast_home
      response_variable: daily
    - name: Weather Forecast Daily
      unique_id: weather_forecast_daily
      state: "{{ now().isoformat() }}"
        forecast: "{{ daily['weather.forecast_home'].forecast }}"

After I made an automation that publishes via mqtt this payload template:

{% set forecast = state_attr('sensor.weather_forecast_daily', 'forecast') %}
{% set forecast_hourly = state_attr('sensor.weather_forecast_hourly', 'forecast') %}
  "weather": {
      "forecast": [
        {% for day in forecast %}
          "condition": "{{ day.condition }}",
          "datetime": "{{ day.datetime }}",
          "wind_bearing": {{ day.wind_bearing }},
          "temperature": {{ day.temperature }},
          "templow": {{ day.templow }},
          "wind_speed": {{ day.wind_speed }},
          "precipitation": {{ day.precipitation }},
          "humidity": {{ day.humidity }}
        }{% if not loop.last %},{% endif %}
        {% endfor %}

This solution is far for perfection but it works!