- id: "76b5be94-b91e-4765-94e9-8f43e859b5aa"
  alias: "Awtrix: Send Current Date to Awtrix Clocks with Color Themes"
  trigger:
    # Trigger whenever sensor.date changes
    - platform: state
      entity_id: sensor.date

  action:
    # Set the current day and date
    - service: mqtt.publish
      data:
        topic: "awtrix_clock_1/custom/calendar"
        payload: >
          {% set current_day = states('sensor.date')[8:10] %}
          {% set current_month = now().month %}
          {% set current_date = now().strftime('%b %d').upper() %}

          {% set color = {
            1: '#42A5F5',
            2: '#E91E63',
            3: '#4CAF50',
            4: '#00BCD4',
            5: '#FFEB3B',
            6: '#FF9800',
            7: '#F44336',
            8: '#00E5FF',
            9: '#FFC107',
            10: '#FF5722',
            11: '#795548',
            12: '#FF1744'
          }[current_month] %}

          {
            "draw": [
              {"df": [0,2,9,7, "#FFFFFF"]},
              {"df": [0,0,9,2, "#FF0000"]},
              {"dt": [1, 2, "{{current_day}}", "#000000"]},
              {"dt": [10, 1, "{{current_date}}", "{{color}}"]}
            ],
            "pos": 1
          }
        qos: 0
        retain: false