More help with serial port

I try to extract from my Electric meter (French Linky) my consumption date from serial port.

  • HA read the port with ‘plateform serial’ (this works)
  • HA refuse to create slave sensors for tagged data (something is clearly wrong in my config)
  • My meter format is a line format: ‘key-word’ (TAB) value1 (TAB) value2 …
    I find few samples on this blog, but unfortunately I still fail to make it work as I want.

With following config. I create a sensor named ‘enedis’ that display the ASCII line send my my meter. But the slave sensor ‘va_instant’ is not create when at minimum I was expecting ‘VA waiting’

My current understanding is that:

  • serial create a sensor named ‘enedis’ that hold the full line
  • each time a new line arrive it apply the template
  • in template I may create as many sensors as I want depending on the filter I apply

It’s obvious that I mess up somewhere.

sensor:
  - platform: serial
    name: enedis
    serial_port: /dev/ttyAMA0
    baudrate: 9600
    parity: E
    bytesize: 7

  - plaform: template
    sensors:
      va_instant:
        friendly_name: "Consomation VA"
        unit_of_measurement: "VA"
        icon_template: mdi:current-ac
        device_class: current
        value_template: >-
          {% if states('sensor.enedis').startswith('SINSTS') %}
            {{ states('sensor.enedis').split('\t')[1] }}
          {% else %}
            {{ states('VA waiting') }}
          {% endif %}

states() method gets the state of an entity_id. You’re tyring to get the state of ‘VA waiting’, which is not an entity_id.

I’ve done some progress. I now get the value display within sensors. Next issue is how to hide Serial sensor in dashboard because it lack a unique_id. Any idea on how hide serial sensor ?

sensor:
  - platform: serial
    name: Enedis
    serial_port: /dev/ttyAMA0
    baudrate: 9600
    parity: E
    bytesize: 7

  - platform: template
    sensors:

      #debug_enedis:
      #   unique_id: enedis:teleinfo:debug
      #   friendly_name: "Debug Input"
      #   icon_template: mdi:current-ac
      #   device_class: current  
      #   value_template: "{{ states('sensor.enedis') }}"

      enedis_watt:
        unique_id: enedis:teleinfo:watt
        friendly_name: "Conso-VA"
        unit_of_measurement: "VA"
        icon_template: mdi:current-ac
        device_class: current
        value_template: >-
          {% if states('sensor.enedis').startswith('SINSTS') %}
            {{ states('sensor.enedis').split('\t')[1] }}
          {% else %}
            {{ states('sensor.enedis_watt') }}
          {% endif %}

      enedis_amp:
        unique_id: enedis:teleinfo:amp
        friendly_name: "Conso-Amp"
        unit_of_measurement: "A"
        icon_template: mdi:current-ac
        device_class: current
        value_template: >-
          {% if states('sensor.enedis').startswith('IRMS1') %}
            {{ states('sensor.enedis').split('\t')[1] }}
          {% else %}
            {{ states('sensor.enedis_amp') }}
          {% endif %}
                        

ha-serial

I got a partial solution to render data from Enedis/Linky within HA energy dashboard.

Shifting to the new template with sensor ‘state_class’ I now get the data from my electric meter (French Linky) to be rendered within HA energy dashboard. Nevertheless I still fail to set a ‘unique-id’ to serial sensors and thus can not hide it from default builtin dashboard.

Extract configuration.yaml

sensor:
    - platform: serial
      name: linky
      serial_port: /dev/ttyAMA0
      baudrate: 9600
      parity: E
      bytesize: 7
      value_template: >-
        {% set slots = value.split('\t') %}
        {{ slots[0] }},{{ slots[1] }}
 
template:
  - sensor:
    - name: enedis_total
      unit_of_measurement: "kWh"
      device_class: energy  
      state_class: total_increasing
      unique_id: enedis:teleinfo:total
      state: >-
        {% if states('sensor.linky').startswith('EAST') %}
          {{ states('sensor.linky').split(',')[1] | float / 1000 }}
        {% else %}  
          {{ states('sensor.enedis_total') }}
        {% endif %}  

    - name: enedis_watt
      unit_of_measurement: "VA"
      device_class: energy  
      state_class: measurement
      unique_id: enedis:teleinfo:watt
      state: >-
        {% if states('sensor.linky').startswith('SINSTS') %}
           {{ states('sensor.linky').split(',')[1] }}
        {% else %}  
           {{ states('sensor.enedis_watt') }}
        {% endif %}  
1 Like