alias: AWTRIX Notify
fields:
  device:
    name: MQTT Topic
    required: true
    example: awtrix_7bf108
    selector:
      text: null
    description: >-
      The MQTT topic, that was specified in the Clocks MQTT-Section of the
      configuration web interface
    default: awtrix_7bf108
  text:
    name: Text
    required: false
    example: Hello World
    selector:
      template: {}
    description: The notification Text
  icon:
    selector:
      text: {}
    name: Icon
    description: An uploaded icon to be displayed along the notification
  duration:
    selector:
      time: {}
    name: Duration
    description: How long the notification should be displayed
    default: 00:00:05
    required: false
  color:
    selector:
      color_rgb: {}
    name: Color
    description: The color of the Text
    required: false
  rainbow:
    selector:
      boolean: {}
    name: Rainbow
    description: If the text should be drawn in rainbow colors
    required: false
  hold:
    selector:
      boolean: {}
    name: Hold
    description: Whether the notification should block until the top button is pressed
    required: false
  effect:
    selector:
      select:
        multiple: false
        options:
          - BrickBreaker
          - Checkerboard
          - Fireworks
          - PingPong
          - Radar
          - Ripple
          - Snake
          - TwinklingStars
          - TheaterChase
          - ColorWaves
          - SwirlOut
          - SwirlIn
          - LookingEyes
          - Matrix
          - Pacifica
          - Plasma
          - PlasmaCloud
          - MovingLine
    name: Effect
    description: Set's an effect as a background
  overlay:
    selector:
      select:
        options:
          - clear
          - snow
          - rain
          - drizzle
          - storm
          - thunder
          - frost
    name: Overlay
    description: Sets an effect overlay
  linechart:
    selector:
      template: {}
    name: Linechart
    description: Will render the list of values as a linechart
  barchart:
    selector:
      template: {}
    name: Barchart
    description: Will render the list of values as a bar chart
  hexcolor:
    selector:
      text: null
    name: Color as hexadecimal
    description: The Text color bus as a hexadecimal value
description: Displays a notification on the AWTRIX Clock
sequence:
  - alias: Error if barchart and linechart are both selected
    if:
      - condition: template
        value_template: {{ true if barchart else false }}
      - condition: template
        value_template: {{ true if linechart else false }}
    then:
      - stop: You cannot select barchart and linechart at the same time
        error: true
  - alias: Error if color and hexcolor are both selected
    if:
      - condition: template
        value_template: {{ true if color else false }}
      - condition: template
        value_template: {{ true if hexcolor else false }}
    then:
      - stop: You cannot select color and hexcolor at the same time
        error: true
  - variables:
      dur_sec: >-
        {{strptime(duration, %H:%M:%S).second + strptime(duration,
        %H:%M:%S).minute*60 + strptime(duration, %H:%M:%S, 5).hour*3600 if
        duration else 5}}
  - metadata: {}
    data:
      qos: 0
      retain: false
      topic: {{ device }}/notify
      payload: >-
        {text: {{text}}, icon: {{icon}}, duration: {{dur_sec}}, 
        color: {{color if color else "+hexcolor+" if hexcolor else
        '#FFFFFF'}}, rainbow: {{'true' if rainbow else 'false'}}, hold: 
        {{'true' if hold else 'false'}}, effect: {{effect}}, overlay:
        {{overlay}} {{',line: ' if linechart else ''}} {{linechart}}
        {{',bar: ' if barchart else ''}} {{barchart}} }
    action: mqtt.publish
icon: mdi:bell-alert

