Translate MQTT numeric payload to meaningful text

I have an EV charger that uses MQTT to publish its state on a MQTT topic
For example
1 = vehicle connected
2 = vehicle charging
3 = vehicle disconnected

How can I translate the numbers (1,2,3) into meaningful text that I can show in the dashboard?

1 Like

Use a value template in your sensor configuration where you map the numbers to the desired values. Here an example how it could look like:

value_template: >
  {% set map = {
    '1': 'vehicle connected',
    '2': 'vehicle charging',
    '3': 'vehicle disconnected'
  } %}
  {{ map[value] if value in map else 'error' }}

Use a template sensor, .e.g. https://www.home-assistant.io/integrations/template/#renaming-sensor-output

I get the error

missed comma between flow collection entries at line 605, column 6:
{% set map = {
^

Can you show the complete sensor code?

I think I need a comma before the last line

No, I don’t think so,can you share the complete sensor code please?

It was an indentation problem, this works, thanks!

  - platform: mqtt
    name: "Prism stato della porta di ricarica"
    state_topic: "prism/1/state"
    value_template: >
      {% set map = {
      '1': 'nessun veicolo connesso',
      '2': 'veicolo connesso, in attesa di ricaricare',
      '3': 'veicolo in carica',
      '4': 'carica in pausa'
       } %}
       {{ map[value] if value in map else 'error' }}
2 Likes

Hi @jacoscar, I also want to integrate the Cartender Prism inside home assistant, could you share your code?

@P91T here it is

  - platform: mqtt
    name: "Prism hello"
    state_topic: "prism/hello"
  - platform: mqtt
    name: "Prism stato"
    state_topic: "prism/1/state"
    value_template: >
      {% set map = {
      '1': 'nessun veicolo connesso',
      '2': 'veicolo connesso, in attesa di ricaricare',
      '3': 'veicolo in carica',
      '4': 'carica in pausa'
       } %}
       {{ map[value] if value in map else 'error' }}
  - platform: mqtt
    name: "Prism corrente"
    state_topic: "prism/1/amp"
    unit_of_measurement: 'mA'
  - platform: mqtt
    name: "Prism wh sessione"
    state_topic: "prism/1/wh"
    unit_of_measurement: 'Wh'
  - platform: mqtt
    name: "Prism corrente pilotata dall’auto"
    state_topic: "prism/1/pilot"
    unit_of_measurement: 'A'
  - platform: mqtt
    name: "Prism user_amp"
    state_topic: "prism/1/user_amp"
    unit_of_measurement: 'A'
  - platform: mqtt
    name: "Prism tensione attuale"
    state_topic: "prism/1/volt"
    unit_of_measurement: 'V'
  - platform: mqtt
    name: "Prism potenza"
    state_topic: "prism/1/w"
    unit_of_measurement: 'W'
  - platform: mqtt
    name: "Prism energia totale"
    state_topic: "prism/1/wh_total"
    unit_of_measurement: 'Wh'
  - platform: mqtt
    name: "Prism durata sessione"
    state_topic: "prism/1/session_time"
    unit_of_measurement: 's'
  - platform: mqtt
    name: "Prism error"
    state_topic: "prism/1/error"
  - platform: mqtt
    name: "Prism mode"
    state_topic: "prism/1/mode"
    value_template: >
      {% set map = {
      '1': 'Solare',
      '2': 'Normale',
      '3': 'Pausa',
      '7': 'Pausa causata da autolimit'
       } %}
       {{ map[value] if value in map else 'error' }}  
  - platform: mqtt
    name: "Prism temperatura"
    state_topic: "prism/0/info/temperature/cover"
    unit_of_measurement: '°C'
  - platform: mqtt
    name: "Prism Tocco"
    state_topic: "prism/1/input/touch"
  - platform: mqtt
    name: "Prism Bussata"
    state_topic: "prism/0/input/knock"
  - platform: mqtt
    name: "Prism power grid"
    state_topic: "prism/energy_data/power_grid"
    unit_of_measurement: 'W'
` ` `
2 Likes

Thank you so much!
do you like to start writing an integration so other users could add prism to their hass instace with the simplicity of downloading a custom component?
I’m not very experienced but there is a lot of documentation and I think we could try!

Don’t wanna sound rude, but if OP doesn’t even know how to use the mapping solution I provided, I doubt he has the skills to create a cudtom component.

You’re right, and I don’t have time :grin:

I am receiving a PRISM soon, any recommendations on how to integrate it

Hi, how did you implement MQTT input and MQTT command from PRISM?