Scripts to interact with Awtrix 3 devices

Since I wasn’t happy with neither the custom_components nor the blueprints that exist to interact with Awtrix 3 devices, I created a bunch of scripts that do the same that I call in automations.

They’re not polished but good enough.
Of course, there’s also some LLM-jank in there :slight_smile:

Feel free to iterate on them.

First of all, notifications:

alias: Awtrix Notify
description: Push notification to specific Awtrix device(s)
fields:
  devices:
    name: AWTRIX Device(s)
    description: The Awtrix device(s) to send the notification to.
    required: true
    selector:
      device:
        integration: mqtt
        manufacturer: Blueforcer
        model: AWTRIX 3
        multiple: true
  data:
    name: Payload Data
    description: The notification payload. See Awtrix Light docs for parameters.
    required: true
    selector:
      object: {}
sequence:
  - variables:
      payload_json_string: "{{ data | to_json }}"
      topics: |-
        {%- macro get_device_topic(device_id) %}
          {{ states((device_entities(device_id) | select('search','device_topic') | list)[0]) }}
        {%- endmacro %}

        {%- set ns = namespace(devices=[]) %}
        {%- for device_id in devices %}
          {%- set device=get_device_topic(device_id)| trim %}
          {% set ns.devices = ns.devices + [ device ~ '/notify' ] %}
        {%- endfor %} {{ ns.devices }}
  - repeat:
      for_each: "{{ topics }}"
      sequence:
        - data:
            qos: 0
            retain: false
            topic: "{{ repeat.item }}"
            payload: "{{ payload_json_string }}"
          action: mqtt.publish
mode: parallel

And here’s the wrapper script that sends notifications via all awtrix devices available:

alias: All Awtrix Notify
description: Sends the same notification to all Awtrix devices
fields:
  data:
    name: Payload Data
    description: The notification payload. See Awtrix Light docs for parameters.
    required: true
    selector:
      object: {}
sequence:
  - variables:
      target_awtrix_device_ids: >
        {{ integration_entities('mqtt') | map('device_id') | reject('none') |
        select('is_device_attr','model','AWTRIX 3') |
        select('is_device_attr','manufacturer','Blueforcer') | unique | list }}
  - data:
      devices: "{{ target_awtrix_device_ids }}"
      data: "{{ data }}"
    action: script.awtrix_notify

The idea for the rest is exactly the same.
To not bloat this post too much, they’re all in spoilers

Custom Apps
alias: Awtrix Push App Data
description: (Un-)publish a custom app on selected Awtrix devices
fields:
  devices:
    name: AWTRIX Device(s)
    description: The Awtrix device(s) to manage the app on.
    required: true
    selector:
      device:
        integration: mqtt
        manufacturer: Blueforcer
        model: AWTRIX 3
        multiple: true
  name:
    name: Custom App Name
    description: The name of the custom app.
    required: true
    selector:
      text: {}
  data:
    name: Payload Data
    description: App configuration data (JSON object). Leave empty to delete the app. See Awtrix Light docs.
    required: false
    selector:
      object: {}
sequence:
  - variables:
      payload_json_string: "{{ data | to_json }}"
      topics: |-
        {%- macro get_device_topic(device_id) %}
          {{ states((device_entities(device_id) | select('search','device_topic') | list)[0]) }}
        {%- endmacro %}

        {%- set ns = namespace(devices=[]) %}
        {%- for device_id in devices %}
          {%- set device=get_device_topic(device_id)| trim %}
          {% set ns.devices = ns.devices + [ device ~ '/custom/' ~ name] %}
        {%- endfor %} {{ ns.devices }}
  - repeat:
      for_each: "{{ topics }}"
      sequence:
        - data:
            qos: 0
            retain: false
            topic: "{{ repeat.item }}"
            payload: "{{ payload_json_string }}"
          action: mqtt.publish
mode: parallel

And the multi one:

alias: All Awtrix Push App Data
description: Pushes the same app data (or deletes app) on all Awtrix devices
fields:
  name:
    name: Custom App Name
    description: The name of the custom app.
    required: true
    selector:
      text: {}
  data:
    name: Payload Data
    description: App configuration data (JSON object). Leave empty to delete the app. See Awtrix Light docs.
    required: false
    selector:
      object: {}
sequence:
  - variables:
      target_awtrix_device_ids: >
        {{ integration_entities('mqtt') | map('device_id') | reject('none') |
        select('is_device_attr','model','AWTRIX 3') |
        select('is_device_attr','manufacturer','Blueforcer') | unique | list }}
  - data:
      devices: "{{ target_awtrix_device_ids }}"
      name: "{{ name }}"
      data: "{{ data }}"
    action: script.awtrix_push_app_data
RTTTL
alias: Awtrix RTTTL
description: Play an RTTTL tone on selected Awtrix device(s)
fields:
  devices:
    name: AWTRIX Device(s)
    description: The Awtrix device(s) to play the tone on.
    required: true
    selector:
      device:
        integration: mqtt
        manufacturer: Blueforcer
        model: AWTRIX 3
        multiple: true
  rtttl:
    name: RTTTL String
    description: The RTTTL string to play.
    required: true
    selector:
      text: null
sequence:
  - variables:
      topics: |-
        {%- macro get_device_topic(device_id) %}
          {{ states((device_entities(device_id) | select('search','device_topic') | list)[0]) }}
        {%- endmacro %}

        {%- set ns = namespace(devices=[]) %}
        {%- for device_id in devices %}
          {%- set device=get_device_topic(device_id)| trim %}
          {% set ns.devices = ns.devices + [ device ~ '/rtttl' ] %}
        {%- endfor %} {{ ns.devices }}
  - repeat:
      for_each: "{{ topics }}"
      sequence:
        - data:
            qos: 0
            retain: false
            topic: "{{ repeat.item }}"
            payload: "{{ rtttl }}"
          action: mqtt.publish
mode: parallel

Multi:

alias: All Awtrix RTTTL
description: Plays the same RTTTL tone on all Awtrix devices simultaneously
fields:
  rtttl:
    name: RTTTL String
    description: The RTTTL string to play.
    required: true
    selector:
      text:
        multiline: true
sequence:
  - variables:
      target_awtrix_device_ids: >
        {{ integration_entities('mqtt') | map('device_id') | reject('none') |
        select('is_device_attr','model','AWTRIX 3') |
        select('is_device_attr','manufacturer','Blueforcer') | unique | list }}
  - data:
      devices: "{{ target_awtrix_device_ids }}"
      rtttl: "{{ rtttl }}"
    action: script.awtrix_rtttl

Switch to App
alias: Awtrix Switch App
description: Switch selected Awtrix device(s) to a specific app
fields:
  devices:
    name: AWTRIX Device(s)
    description: The Awtrix device(s) to switch the app on.
    required: true
    selector:
      device:
        integration: mqtt
        manufacturer: Blueforcer
        model: AWTRIX 3
        multiple: true
  name:
    name: App Name
    description: The name of the app to switch to
    required: true
    selector:
      text: null
sequence:
  - variables:
      topics: |-
        {%- macro get_device_topic(device_id) %}
          {{ states((device_entities(device_id) | select('search','device_topic') | list)[0]) }}
        {%- endmacro %}

        {%- set ns = namespace(devices=[]) %}
        {%- for device_id in devices %}
          {%- set device=get_device_topic(device_id)| trim %}
          {% set ns.devices = ns.devices + [ device ~ '/switch' ] %}
        {%- endfor %} {{ ns.devices }}
  - repeat:
      for_each: "{{ topics }}"
      sequence:
        - data:
            qos: 0
            retain: false
            topic: "{{ repeat.item }}"
            payload: "{ \"name\": \"{{ name }}\" }"
          action: mqtt.publish
mode: parallel

Multi:

alias: All Awtrix Switch App
description: Switches all Awtrix devices to the specified app
fields:
  name:
    name: App Name
    description: The name of the app to switch to
    required: true
    selector:
      text: {}
sequence:
  - variables:
      target_awtrix_device_ids: >
        {{ integration_entities('mqtt') | map('device_id') | reject('none') |
        select('is_device_attr','model','AWTRIX 3') |
        select('is_device_attr','manufacturer','Blueforcer') | unique | list }}
  - data:
      devices: "{{ target_awtrix_device_ids }}"
      name: "{{ name }}"
    action: script.awtrix_switch_app
Settings
alias: Awtrix Settings
description: Push settings to selected Awtrix device(s)
fields:
  devices:
    name: AWTRIX Device(s)
    description: The Awtrix device(s) to apply settings to.
    required: true
    selector:
      device:
        integration: mqtt
        manufacturer: Blueforcer
        model: AWTRIX 3
        multiple: true
  data:
    name: Payload Data
    description: Settings payload (JSON object). See Awtrix Light docs for parameters.
    required: true
    selector:
      object: {}
sequence:
  - variables:
      payload_json_string: "{{ data | to_json }}"
      topics: |-
        {%- macro get_device_topic(device_id) %}
          {{ states((device_entities(device_id) | select('search','device_topic') | list)[0]) }}
        {%- endmacro %}

        {%- set ns = namespace(devices=[]) %}
        {%- for device_id in devices %}
          {%- set device=get_device_topic(device_id)| trim %}
          {% set ns.devices = ns.devices + [ device ~ '/settings' ] %}
        {%- endfor %} {{ ns.devices }}
  - repeat:
      for_each: "{{ topics }}"
      sequence:
        - data:
            qos: 0
            retain: false
            topic: "{{ repeat.item }}"
            payload: "{{ payload_json_string }}"
          action: mqtt.publish
mode: parallel

Multi:

alias: All Awtrix Settings
description: Apply the same settings to all Awtrix devices
fields:
  data:
    name: Payload Data
    description: Settings payload (JSON object). See Awtrix Light docs for parameters.
    required: true
    selector:
      object: {}
sequence:
  - variables:
      target_awtrix_device_ids: >
        {{ integration_entities('mqtt') | map('device_id') | reject('none') |
        select('is_device_attr','model','AWTRIX 3') |
        select('is_device_attr','manufacturer','Blueforcer') | unique | list }}
  - data:
      devices: "{{ target_awtrix_device_ids }}"
      data: "{{ data }}"
    action: script.awtrix_settings

2 Likes