Weather from Home Assistant Entity
Home Assistant

Weather from Home Assistant Entity

This automation triggers whenever the weather entity changes and it'll sent weather and humidity data for Kamloops to two Awtrix clocks via MQTT. It dynamically selects appropriate weather icons based on the current conditions (e.g., clear, cloudy, rainy) and sends the temperature and humidity in JSON format to both clocks.
A flow by Colton Dick

Go to automations Download flow Download assets

Flow Details

Set Weather from Home Assistant Entity

This Home Assistant automation, titled "Set Weather from Home Assistant Entity", is designed to publish current weather and humidity data for Kamloops to two Awtrix clocks using MQTT. The automation runs every 15 minutes and sends the data in a JSON format, allowing the clocks to display up-to-date information about temperature, humidity, and weather conditions.

Key Features:

  1. Trigger:

    • The automation is set to trigger whenever the weather entity changes, ensuring that both Awtrix clocks are updated regularly with the latest weather data.
  2. MQTT Publishing:

    • The automation uses the mqtt.publish service to send MQTT messages to the topics awtrix_clock_1/custom/weather, awtrix_clock_2/custom/weather, awtrix_clock_1/custom/humidity, and awtrix_clock_2/custom/humidity.
    • The payload for each message is dynamically generated based on the current weather conditions and humidity.
  3. Dynamic Weather Icon Selection:

    • The automation selects an appropriate icon based on the current weather conditions in Kamloops. For instance:
      • Clear sky (day) uses icon 2282.
      • Clear sky (night) uses icon 12181.
      • Partly cloudy uses icon 53384.
      • Cloudy uses icon 53802.
      • Rain uses icon 2284.
      • Lightning uses icon 49299.
      • Snow uses icon 2289.
      • Fog uses icon 17055.
    • This ensures that the clocks display relevant visuals based on real-time weather data.
  4. Temperature and Humidity:

    • The temperature data is displayed alongside the weather icon in Celsius (e.g., "22°C").
    • Humidity is sent as a percentage with a dedicated icon 2423, displaying values like "45%" on the clock.
  5. Multiple Clocks:

    • The automation updates two separate Awtrix clocks (awtrix_clock_1 and awtrix_clock_2), ensuring that both devices are synchronized and show the same information.
  6. Customization:

    • The MQTT message has fields like repeat, icon, and text, allowing customization of the display on the Awtrix devices. The repeat value is set to 1, ensuring that the display information is updated regularly without excessive repetition.

Technical Overview:

  • The automation relies on the weather.kamloops entity, which retrieves weather information for Kamloops through an integration like OpenWeatherMap.
  • The mqtt.publish service sends structured JSON payloads to the specified topics, ensuring that both temperature and humidity data are transmitted to the clocks.
  • With each run of the automation, both Awtrix clocks receive fresh data and update their displays accordingly, providing real-time, visually rich feedback about the current weather and environmental conditions.

This automation ensures that your Awtrix clocks stay up-to-date with weather and humidity data, providing a seamless integration with Home Assistant through MQTT.

- id: "9e9a62c9-ccaa-4b89-b6d9-c68647dfaed7" alias: Update Awtrix Weather on Weather Change trigger: - platform: state entity_id: weather.kamloops action: - service: mqtt.publish data: topic: "awtrix_clock_1/custom/weather" payload: > {% set temperature = state_attr('weather.kamloops', 'temperature') %} {% set condition = states('weather.kamloops') %} {% set color = [0, 255, 0] %} {% if temperature > 30 %} {% set color = [255, 0, 0] %} {% elif temperature < 0 %} {% set color = [0, 0, 255] %} {% endif %} {% set icon = 2282 %} {% if condition == 'clear-night' %} {% set icon = 12181 %} {% elif condition == 'partlycloudy' %} {% set icon = 53384 %} {% elif condition == 'cloudy' %} {% set icon = 53802 %} {% elif condition == 'rainy' %} {% set icon = 2284 %} {% elif condition == 'lightning' %} {% set icon = 49299 %} {% elif condition == 'snowy' %} {% set icon = 2289 %} {% elif condition == 'fog' %} {% set icon = 17055 %} {% endif %} { "repeat": 1, "icon": {{ icon }}, "text": "{{ temperature }}°C", "color": {{ color }} } qos: 0 retain: false - service: mqtt.publish data: topic: "awtrix_clock_2/custom/weather" payload: > {% set temperature = state_attr('weather.kamloops', 'temperature') %} {% set condition = states('weather.kamloops') %} {% set color = [0, 255, 0] %} {% if temperature > 30 %} {% set color = [255, 0, 0] %} {% elif temperature < 0 %} {% set color = [0, 0, 255] %} {% endif %} {% set icon = 2282 %} {% if condition == 'clear-night' %} {% set icon = 12181 %} {% elif condition == 'partlycloudy' %} {% set icon = 53384 %} {% elif condition == 'cloudy' %} {% set icon = 53802 %} {% elif condition == 'rainy' %} {% set icon = 2284 %} {% elif condition == 'lightning' %} {% set icon = 49299 %} {% elif condition == 'snowy' %} {% set icon = 2289 %} {% elif condition == 'fog' %} {% set icon = 17055 %} {% endif %} { "repeat": 1, "icon": {{ icon }}, "text": "{{ temperature }}°C", "color": {{ color }} } qos: 0 retain: false - service: mqtt.publish data: topic: "awtrix_clock_1/custom/humidity" payload: > {% set humidity = state_attr('weather.kamloops', 'humidity') %} { "repeat": 1, "icon": 2423, "text": "{{ humidity }}%" } qos: 0 retain: false - service: mqtt.publish data: topic: "awtrix_clock_2/custom/humidity" payload: > {% set humidity = state_attr('weather.kamloops', 'humidity') %} { "repeat": 1, "icon": 2423, "text": "{{ humidity }}%" } qos: 0 retain: false
/flows/zB23Oe9pOrLJ/53802.gif
/flows/zB23Oe9pOrLJ/53384.gif
/flows/zB23Oe9pOrLJ/49300.gif
/flows/zB23Oe9pOrLJ/49299.gif
/flows/zB23Oe9pOrLJ/17055.gif
/flows/zB23Oe9pOrLJ/12181.gif
/flows/zB23Oe9pOrLJ/2423.gif
/flows/zB23Oe9pOrLJ/2289.gif
/flows/zB23Oe9pOrLJ/2284.gif
/flows/zB23Oe9pOrLJ/2282.gif
-- Flow first published on October 12, 2024, last updated on October 12, 2024 at 23:52.