Rename MQTT State Shelly

Hi guys,

i want to rename the state from MQTT for one of my Shelly devices in the frontend.

my Configuration is:

  - platform: mqtt
    name: "Shelly DW2 Status"
    state_topic: "shellies/shellydw2-x/sensor/state"

Its “closed” or “open”.
Want to rename it to my German Language.
Thanks

How can i rename the status in the ui , with Template sensor or directly in the MQTT Section?

sw321

Try this:

  - platform: mqtt
    name: "Shelly DW2 Status"
    state_topic: "shellies/shellydw2-x/sensor/state"
    value_template: "{{ 'offen' if value == 'open' else 'geschlossen' }}"

This template assumes there are only two states reported by the Shelly device (open/closed). If there are more states reported then the template will need to be enhanced.

Alternatively, you could define the sensor as a binary_sensor, and specify the proper device_class.
Then, translation would happen automatically.

This approach has the advantage of keeping your automations generic, rather than potentially comparing to a translated state.

Here’s an example of koying’s suggestion to use an MQTT Binary Sensor:

  - platform: mqtt
    name: "Shelly DW2 Status"
    state_topic: "shellies/shellydw2-x/sensor/state"
    value_template: "{{ 'ON' if value == 'open' else 'OFF' }}"
    device_class: garage_door

The choice between using an MQTT Sensor and an MQTT Binary Sensor depends on the application. If the Shelly device only reports two states then you may as well model it as an MQTT Binary Sensor. Otherwise model it as an MQTT Sensor which permits more than two states and the state names can be whatever you want.

Thanks, that works fine!
Brilliant guys!
Thank you !!!

You’re welcome. However you should mark koying’s post with the Solution tag because it was the first to suggest using an MQTT Binary Sensor with a device_class.

1 Like

Yes - done!
Thanks!

Thanks for helping guys!