#Send and receive the entire weather entity including attributes via MQTT

3 messages · Page 1 of 1 (latest)

spice pond
#

As part of a larger integration we need to get weather forecasts on a significant scale, therefore the decision was made to run 1 home assistant as our own "server".
This home assistant then gets the weather forecast from pirateweather, the state is the current general state (i.e. "Cloudy") with the predictions being stored in attributes to that state.
The individual clients can then all get their data from that server, removing a lot of unnecessary external API calls.

Our idea was to send the states via MQTT, a relatively simple excercise using the following 2 code blocks:
Server automations.yaml:

  alias: haco Publishes sensor values to the MQTT broker
  description: ''
  trigger:
  - platform: time_pattern
    minutes: /20
  action:
  - action: mqtt.publish
    data_template:
      topic: location/temperature
      payload: '{{ states(''sensor.location_temperature'')}}'#location is replaced by actual location

Client configuration.yaml:#for now

  sensor:
    - name: "mqtt_temperature"
      state_topic: "location/temperature"```

This works well with entities where the state contains all the information we need, however with the weather object it appears that the data is stored in the attribute.
I am unclear on how to send the attributes on the server, and correctly parse them on the client.

I have also looked in the MQTT statestream, however based on external listeners like MQTTX or MQTT explorer this is also only sending the state, not the attributes.

Any help is much appreciated.
If you feel like I should use something other than MQTT to send this information then please let me know as well.

Greetings,
Ylva
spice pond
#

okay it seems that sending it via a statestream is quite easy: ```mqtt_statestream:
base_topic: hetzner
publish_attributes: true
publish_timestamps: false
include:
entities:
- sensor.temperature

This shows the attributes correctly in the MQTTX explorer. However I am now no longer able to read it on client side using 
```mqtt:
  sensor:
    - name: "mqtt_temperature"
      state_topic: "hetzner/sensor/temperature"```