Template message or friendly name question

Hi Guys

I have several automations that use TTS to report the state of various entities etc.

I normally use something basic like this within the TTS message:

{{ states(‘alarm_control_panel.house’) }}

I would like to smarten them up a little and I gather if I add friendly names to entities, groups etc then I can have it read them out instead, so two questions really:

1: can some show me an example of the template needed to show the friendly name or point me to some reading that will.

2: in the above example i dont believe I can set a friendly name for the state’s, so how could I template the different alarm states so as to avoid the phrase I hear every night of “alarm has been set to armed underscore night”

As always thanks in advance

Ps I really really want to learn more about templating in HA but struggle to find any reading that’s not completely over my head.

Replace underscores with spaces.

{{ states('alarm_control_panel.house').replace('_', ' ') }}

Only an entity can have a friendly_name, not an entity’s state value. This will display your alarm panel’s friendly name:

{{ state_attr('alarm_control_panel.house', 'friendly_name')  }}
1 Like

Perfect, have never used replace before so that will come in handy for a few of my automations for sure.

With regards my 2nd question, I think maybe I worded it badly, what I was wondering if it is possible to make a template TTS that uses:

If this state then say “xyz” else if this state say “abc” so that I can specify the message based on each state. Hopefully that makes more sense

A simple example that demonstrates the use a dict to translate the alarm_panel’s state value into something different. For example, “armed_home” is reported as “occupied protected”. Feel free to change the phrases to whatever you prefer.

alias: example 333
trigger:
- platform: state
  entity_id: alarm_control_panel.house
action:
- platform: notify.persistent_notification
  data:
    message: >
        {% set msgs = { 'disarmed': 'unprotected', 'armed_home': 'occupied protected', 'armed_away': 'unoccupied protected',
                        'armed_night': 'night sentry', 'armed_custom_bypass': 'special protection', 'pending': 'working',
                        'triggered': 'Red Alert!', 'arming': 'about to protect', 'disarming': 'about to unprotect' }
        Alarm panel says: {{ msgs[trigger.to_state.state] if trigger.to_state.state in msgs.keys() else 'unknown' }}
1 Like

Perfect thank you very much, I would love to learn templating better than just googling or asking on forum but struggle to find anything to read other than the default home assistant docs.

Trouble is as each time I learn a little more I end up going back and rewriting half my automations and scripts, sometime it outwardly changes nothing but in my head I have made it smarter as I have sometimes reduced multiple lines in to one.

Now if I could just get out this rabbit hole…

1 Like