Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 105651

Change numeric sensor states to text

$
0
0

Hello,

I have a modbus sensor that returns numeric state values, each value representing a specific mode of operation. I would like to translate those numeric values over to a text description of the operating mode. The following code in configuration.yaml returns the modbus numeric values as expected:

modbus:
  name: AXSPort
  type: tcp
  host: 192.168.1.37
  port: 502

sensor:
  platform: modbus
  scan_interval: 10
  registers:
    - name: Outback_Operating_Mode
      hub: AXSPort
      register: 41517

Then, based on this thread https://community.home-assistant.io/t/wanting-to-map-sensor-number-value-to-words/40663/7 I tried tacking on the " - platform: template" section as seen here.

modbus:
  name: AXSPort
  type: tcp
  host: 192.168.1.37
  port: 502

sensor:
  platform: modbus
  scan_interval: 10
  registers:
    - name: Outback_Operating_Mode
      hub: AXSPort
      register: 41517

  - platform: template
    sensors:
      outback_operating_mode_text:
      friendly_name: "Outback_Operating_Mode_Text"
        unit_of_measurement: "State"
        entity_id: sensor.outback_operating_mode
        value_template: >-
          {% set mapper =  {
              '0' : 'Off',
              '1' : 'Searching',
              '2' : 'Inverting',
              '3' : 'Charging',
              '4' : 'Silent',
              '5' : 'Float',
              '6' : 'EQ',
              '7' : 'Charger Off',
              '8' : 'Support',
              '9' : 'Selling',
              '10' : 'Pass Through',
              '11' : 'Offsetting' } %}
          {% set state =  states.sensor.outback_operating_mode.state %}
          {{ mapper[state] if state in mapper else 'Unknown' }}

Unfortunately, this configuration fails validation:
image

Guessing the problem is a fairly basic oversight on my part, but I’m pretty new at this. Any guidance would be appreciated.

Thanks!

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 105651

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>