- 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