Basic template question - # value to text

I have a conditional card show when my vacuum is in “error” state, i also have an entity which states the error as a raw, numerical value (1,2,4,6,8,etc)

I can’t get my head around templates yet but i know its possible to translate the number value into a message and i know what i want to say but can’t write the template to do it as i dont understand it just yet

I have an automation to notify me of the errors which works well, i just want a conditional card to say the same thing as my notification does…

YAML for my automation…

description: ""
trigger:
  - platform: state
    entity_id:
      - vacuum.cybovac
    to: error
condition: []
action:
  - if:
      - condition: state
        entity_id: sensor.cybovac_fault
        state: "1"
    then:
      - service: notify.notify
        data:
          message: Cliff Error
          title: Cybovac
  - if:
      - condition: state
        entity_id: sensor.cybovac_fault
        state: "2"
    then:
      - service: notify.notify
        data:
          message: Roller Brush Error
          title: Cybovac
  - if:
      - condition: state
        entity_id: sensor.cybovac_fault
        state: "4"
    then:
      - service: notify.notify
        data:
          message: Left Wheel Fault
          title: Cybovac
  - if:
      - condition: state
        entity_id: sensor.cybovac_fault
        state: "8"
    then:
      - service: notify.notify
        data:
          message: Right Wheel Fault
          title: Cybovac
  - if:
      - condition: state
        entity_id: sensor.cybovac_fault
        state: "16"
    then:
      - service: notify.notify
        data:
          message: Bin Full
          title: Cybovac
  - if:
      - condition: state
        entity_id: sensor.cybovac_fault
        state: "32"
    then:
      - service: notify.notify
        data:
          message: Edge Brush Fault
          title: Cybovac
  - if:
      - condition: state
        entity_id: sensor.cybovac_fault
        state: "64"
    then:
      - service: notify.notify
        data:
          message: Collision Error
          title: Cybovac
mode: single

Please format your post correctly https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

1 Like

You can reduce the automation to this:

alias: example 
trigger:
  - platform: state
    entity_id:
      - vacuum.cybovac
    to: error
condition: []
action:
  - service: notify.notify
    data:
      message: >
         {% set messages =
           { '1': 'Cliff Error',
             '2': 'Roller Brush Error',
             '4': 'Left Wheel Fault',
             '8': 'Right Wheel Fault',
             '16': 'Bin Full',
             '32': 'Edge Brush Fault',
             '64': 'Collision Error' } %}
         {{ messages.get(states('sensor.cybovac_fault'), 'unknown') }}
      title: Cybovac
mode: single

The template in this example can be used elsewhere such as in a Trigger-based Template Sensor or in a Markdown card, etc