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.
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' }}
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.