Advertisement
madswestermann

Script Fields

Feb 21st, 2025 (edited)
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 2.53 KB | Source Code | 0 0
  1. alias: Send Custom App to Awtrix
  2. description: Sends an MQTT message to Awtrix3 to create or delete a custom app
  3. fields:
  4.   topic:
  5.     name: Topic
  6.     description: The Awtrix custom app topic (without prefix)
  7.     required: true
  8.     example: my_custom_app
  9.   text:
  10.     name: Text
  11.     description: Text to display on Awtrix
  12.     default: ""
  13.     example: Hello World
  14.   color:
  15.     name: Color
  16.     description: Text color in hex format
  17.     default: "#FFFFFF"
  18.     example: "#FF0000"
  19.   background:
  20.     name: Background
  21.     description: Background color in hex format
  22.     default: "#000000"
  23.     example: "#0000FF"
  24.   hold:
  25.     name: Hold
  26.     description: Keep app displayed until manually removed
  27.     default: false
  28.     selector:
  29.       boolean: null
  30.   lifetime:
  31.     name: Lifetime
  32.     description: How long the app stays active (seconds)
  33.     default: 3600
  34.     selector:
  35.       number:
  36.         min: 1
  37.         max: 86400
  38.         unit_of_measurement: seconds
  39.   lifetimeMode:
  40.     name: Lifetime Mode
  41.     description: Mode for lifetime behavior
  42.     default: 0
  43.     selector:
  44.       number:
  45.         min: 0
  46.         max: 2
  47.   retain:
  48.     name: Retain
  49.     description: Whether to retain the MQTT message
  50.     default: false
  51.     selector:
  52.       boolean: null
  53.   qos:
  54.     name: QoS
  55.     description: Quality of Service level for MQTT message
  56.     default: "2: Exactly once"
  57.     selector:
  58.       select:
  59.         options:
  60.           - "0: Fire and forget"
  61.          - "1: At least once"
  62.          - "2: Exactly once"
  63. sequence:
  64.  - variables:
  65.      mqtt_topic: awtrix_52ec44/custom/{{ topic }}
  66.      mqtt_qos: "{{ qos.split(':')[0] | int }}"
  67.      mqtt_retain: "{{ true if text == '' else retain }}"
  68.  - choose:
  69.      - conditions:
  70.          - condition: template
  71.            value_template: "{{ text | length > 0 }}"
  72.        sequence:
  73.          - data:
  74.              topic: "{{ mqtt_topic }}"
  75.              payload: |-
  76.                {
  77.                  "text": "{{ text }}",
  78.                  "color": "{{ color }}",
  79.                  "background": "{{ background }}",
  80.                  "hold": {{ hold | lower }},
  81.                  "lifetime": {{ lifetime }},
  82.                  "lifetimeMode": {{ lifetimeMode }}
  83.                }
  84.              qos: "{{ mqtt_qos }}"
  85.              retain: "{{ mqtt_retain }}"
  86.            action: mqtt.publish
  87.    default:
  88.      - data:
  89.          topic: "{{ mqtt_topic }}"
  90.          payload: ""
  91.          qos: "{{ mqtt_qos }}"
  92.          retain: "{{ mqtt_retain }}"
  93.        action: mqtt.publish
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement