I set up an automation to send me a notification whenever my vacuum cleaner changes its “error” state to one of the many pre-configured errors. I got the German translation running in Home Assistant, so I would have expected that message to be also in German. Instead my automation sends me the original English state which results in a language mix in my notification.This is what I have:
German translation in Home Assistant is “Keine”, the entity shows these translated entries everywhere except in the YAML file. So is there a way to get this done without messing around too much and just taking the translations that are already in the system?
And how do you do that? With if […] then for each state? I was hoping there would be an additional parameter to have the translation in the current language.
Okay, thank you, at least I know that now. Time for a little {% if %} … {% elif %} {% else %} I guess. Starting to learn the syntax, maybe a good time to practice.
This is my solution now, based on your translation @pedolsky
service: notify.notify
data:
title: Gerätefehler
message: >-
Der Staubsauger hat ein Problem erkannt:
{% set error_message = {'lidar_blocked': 'Lidar blockiert',
'bumper_stuck': 'Stoßfänger klemmt',
'wheels_suspended': 'Räder aufgehängt',
'main_brush_jammed': 'Hauptbürste eingeklemmt',
'side_brush_jammed': 'Seitenbürste eingeklemmt',
'wheels_jammed': 'Räder klemmen',
'robot_trapped': 'Roboter gefangen',
'no_dustbin': 'Kein Mülleimer',
'low_battery': 'Niedriger Batteriestatus',
'charging_error': 'Ladefehler',
'battery_error': 'Batteriefehler',
'wall_sensor_dirty': 'Wandsensor verschmutzt',
'robot_tilted': 'Roboter umgekippt',
'side_brush_error': 'Fehler Seitenbürste',
'fan_error': 'Lüfterfehler',
'vertical_bumper_pressed': 'Vertikaler Stoßfänger gedrückt',
'dock_locator_error': 'Roboter findet die Ladestation nicht',
'return_to_dock_fail': 'Rückkehr zur Ladestation fehlgeschlagen',
'nogo_zone_detected': 'Sperrzone erkannt',
'vibrarise_jammed': 'VibraRise blockiert',
'robot_on_carpet': 'Roboter auf Teppich',
'filter_blocked': 'Filter verstopft',
'invisible_wall_detected': 'Unsichtbare Wand erkannt',
'cannot_cross_carpet': 'Teppich kann nicht überquert werden',
'internal_error': 'Interner Fehler', '': '', '': ''} %}
{% set error_state = states('sensor.vacuum_error') %}
{% if error_state in error_message %} {{ error_message[error_state] }}
{% else %} {{ error_state }}
{% endif %}
alias: Benachrichtigung
I excluded several states from the trigger like “none”, “unknown” and “unavailable” since I got another automation for devices being offline. I also made sure that a status that I didn’t include would be displayed but in English. Just in case there is an update where the state names change or if I made a mistake.
I got all the states’ names from simply choosing them from the list and then checking the YAML file, one by one. I didn’t find an easier way. If there is one, let me know.