Integration of Shelly ProEM50 into Homeassistant - YAML-scirpt does not work

Hi all,

I am trying to integrate my ShellyProEM50 into Homeassistant using a configuration.yaml but for any reason I don’t understand the entity “Energieverbrauch Heizung” and “Energy Total Heizung” don’t show up in the list of entities…

Here a copy of my yaml-script - hope you guys have a smart idea what’s wrong - and many thanks in advance for your thoughts / tips / hints !


Loads default set of integrations. Do not remove.

default_config:

frontend:
themes: !include_dir_merge_named themes

Load frontend themes from the themes folder

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

template:
- sensor:
- name: “Energieverbrauch Heizung”
unique_id: power_total_heizung
state: >
{{ states(‘sensor.shellyproem50_08f9e0e68e48_em1_power’)|float(0) +
states(‘sensor.shellyproem50_08f9e0e68e48_em0_power’)|float(0) }}
unit_of_measurement: W
device_class: power
state_class: measurement
availability: >
{{
[ states(‘sensor.shellyproem50_08f9e0e68e48_em1_power’),
states(‘sensor.shellyproem50_08f9e0e68e48_em0_power’) ] | map(‘is_number’) | min }}
- sensor:
- name: “Energy Total Heizung”
unique_id: energy_total_heizung
state: >
{{ states(‘sensor.shellyproem50_08f9e0e68e48_em0_total_active_energy’)|float(0) +
states(‘sensor.shellyproem50_08f9e0e68e48_em1_total_active_energy’)|float(0) }}
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
attributes:
last_reset: “1970-01-01T00:00:00+00:00”
availability: >
{{
[ states(‘sensor.shellyproem50_08f9e0e68e48_em0_total_active_energy’),
states(‘sensor.shellyproem50_08f9e0e68e48_em1_total_active_energy’) ] | map(‘is_number’) | min }}

Please post the yaml as code

Sorry - was trying yesterday already to post it in better format but haven’t been able to find a proper way to get it done properly (until now… )
Thanks very much for this hint and hopefully you have also a smart idea what’s wrong in my code and why the entity doesn’t show up in the list as expected.

Thx Rolf

type or paste code here
```# Loads default set of integrations. Do not remove.
default_config:

frontend:
  themes: !include_dir_merge_named themes
  # Load frontend themes from the themes folder

  automation: !include automations.yaml
  script: !include scripts.yaml
  scene: !include scenes.yaml
  
  template:
     - sensor:
        - name: "Energieverbrauch Heizung"
          unique_id: power_total_heizung
          state: >
            {{ states('sensor.shellyproem50_08f9e0e68e48_em1_power')|float(0) +
               states('sensor.shellyproem50_08f9e0e68e48_em0_power')|float(0) }}
          unit_of_measurement: W
          device_class: power
          state_class: measurement
          availability: >
             {{
                 [ states('sensor.shellyproem50_08f9e0e68e48_em1_power'),
                   states('sensor.shellyproem50_08f9e0e68e48_em0_power') ] | map('is_number') | min }}
     - sensor:
        - name: "Energy Total Heizung"
          unique_id: energy_total_heizung
          state: >
            {{ states('sensor.shellyproem50_08f9e0e68e48_em0_total_active_energy')|float(0) +
               states('sensor.shellyproem50_08f9e0e68e48_em1_total_active_energy')|float(0) }}
          unit_of_measurement: kWh
          device_class: energy
          state_class: total_increasing
          attributes:
            last_reset: "1970-01-01T00:00:00+00:00"
          availability: >
              {{ 
                 [ states('sensor.shellyproem50_08f9e0e68e48_em0_total_active_energy'),
                   states('sensor.shellyproem50_08f9e0e68e48_em1_total_active_energy') ] | map('is_number') | min }}

Where do you look for these entities?

I want to add this entity to a badge and when editing I can select the entity I want to add.

I have done the same thing for a Shelly Pro EM3 and it works… - could also select it from list

Here the yAML-code I use for the EM3


# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

template:
   - sensor:
      - name: "Power Total"
        unique_id: power_total
        state: >
          {{ states('sensor.shellypro3em63_2cbcbbb83640_phase_a_active_power')|float(0) +
             states('sensor.shellypro3em63_2cbcbbb83640_phase_b_active_power')|float(0) +
             states('sensor.shellypro3em63_2cbcbbb83640_phase_c_active_power')|float(0) }}
        unit_of_measurement: W
        device_class: power
        state_class: measurement
        availability: >
           {{
               [ states('sensor.shellypro3em63_2cbcbbb83640_phase_a_active_power'),
                 states('sensor.shellypro3em63_2cbcbbb83640_phase_b_active_power'),
                 states('sensor.shellypro3em63_2cbcbbb83640_phase_c_active_power') ] | map('is_number') | min }}
   - sensor:
      - name: "Energy Total"
        unique_id: energy_total
        state: >
          {{ states('sensor.shellypro3em63_2cbcbbb83640_total_active_energy') }}
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        attributes:
          last_reset: "1970-01-01T00:00:00+00:00"
        availability: >
            {{ 
               [ states('sensor.shellypro3em63_2cbcbbb83640_total_active_energy') ] | map('is_number') | min }}

Can you Show the complete Yaml Code for both?
Start with template: for the first and for the next without

  • What is the point of the “energy total” sensor? You are creating a duplicate of an existing entity with wrong configuration.
  • You should not add last reset attribute to the energy sensors.
  • You should not use a default value for float conversion if you use availability.
  • Try to search for sensor.energieverbrauch_heizung entity in Developer toolsStates

Hi Bieiniu,

the config for the EM3 works perfectly.
The issue I have is with the EM50 - the YAML-script doesn’s show up in the list of entities I can connect - this is what annoys me so much and I don’t understand the reason for.
Here the script for the EM50:

# Loads default set of integrations. Do not remove.
default_config:

frontend:
  themes: !include_dir_merge_named themes
  # Load frontend themes from the themes folder

  automation: !include automations.yaml
  script: !include scripts.yaml
  scene: !include scenes.yaml
  
  template:
     - sensor:
        - name: "Energieverbrauch Heizung"
          unique_id: Energieverbrauch Heizung
          state: >
            {{ states('sensor.shellyproem50_08f9e0e68e48_em1_power')|float(0) +
               states('sensor.shellyproem50_08f9e0e68e48_em0_power')|float(0) }}
          unit_of_measurement: W
          device_class: power
          state_class: measurement
          availability: >
             {{
                 [ states('sensor.shellyproem50_08f9e0e68e48_em1_power'),
                   states('sensor.shellyproem50_08f9e0e68e48_em0_power') ] | map('is_number') | min }}
     - sensor:
        - name: "Energy Total Heizung"
          unique_id: Energy Total Heizung
          state: >
            {{ states('sensor.shellyproem50_08f9e0e68e48_em0_total_active_energy')|float(0) +
               states('sensor.shellyproem50_08f9e0e68e48_em1_total_active_energy')|float(0) }}
          unit_of_measurement: kWh
          device_class: energy
          state_class: total_increasing
          attributes:
            last_reset: "1970-01-01T00:00:00+00:00"
          availability: >
              {{ 
                 [ states('sensor.shellyproem50_08f9e0e68e48_em0_total_active_energy'),
                   states('sensor.shellyproem50_08f9e0e68e48_em1_total_active_energy') ] | map('is_number') | min }}

Here the script for the Shelly EM3 whcih is working:


# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

template:
   - sensor:
      - name: "Power Total"
        unique_id: power_total
        state: >
          {{ states('sensor.shellypro3em63_2cbcbbb83640_phase_a_active_power')|float(0) +
             states('sensor.shellypro3em63_2cbcbbb83640_phase_b_active_power')|float(0) +
             states('sensor.shellypro3em63_2cbcbbb83640_phase_c_active_power')|float(0) }}
        unit_of_measurement: W
        device_class: power
        state_class: measurement
        availability: >
           {{
               [ states('sensor.shellypro3em63_2cbcbbb83640_phase_a_active_power'),
                 states('sensor.shellypro3em63_2cbcbbb83640_phase_b_active_power'),
                 states('sensor.shellypro3em63_2cbcbbb83640_phase_c_active_power') ] | map('is_number') | min }}
   - sensor:
      - name: "Energy Total"
        unique_id: energy_total
        state: >
          {{ states('sensor.shellypro3em63_2cbcbbb83640_total_active_energy') }}
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        attributes:
          last_reset: "1970-01-01T00:00:00+00:00"
        availability: >
            {{ 
               [ states('sensor.shellypro3em63_2cbcbbb83640_total_active_energy') ] | map('is_number') | min }}

and here the script of the Shelly EM50 where I want to add the power measurement of both channels:

# Loads default set of integrations. Do not remove.
default_config:

frontend:
  themes: !include_dir_merge_named themes
  # Load frontend themes from the themes folder

  automation: !include automations.yaml
  script: !include scripts.yaml
  scene: !include scenes.yaml
  
  template:
     - sensor:
        - name: "Energieverbrauch Heizung"
          unique_id: Energieverbrauch Heizung
          state: >
            {{ states('sensor.shellyproem50_08f9e0e68e48_em1_power')|float(0) +
               states('sensor.shellyproem50_08f9e0e68e48_em0_power')|float(0) }}
          unit_of_measurement: W
          device_class: power
          state_class: measurement
          availability: >
             {{
                 [ states('sensor.shellyproem50_08f9e0e68e48_em1_power'),
                   states('sensor.shellyproem50_08f9e0e68e48_em0_power') ] | map('is_number') | min }}
     - sensor:
        - name: "Energy Total Heizung"
          unique_id: Energy Total Heizung
          state: >
            {{ states('sensor.shellyproem50_08f9e0e68e48_em0_total_active_energy')|float(0) +
               states('sensor.shellyproem50_08f9e0e68e48_em1_total_active_energy')|float(0) }}
          unit_of_measurement: kWh
          device_class: energy
          state_class: total_increasing
          attributes:
            last_reset: "1970-01-01T00:00:00+00:00"
          availability: >
              {{ 
                 [ states('sensor.shellyproem50_08f9e0e68e48_em0_total_active_energy'),
                   states('sensor.shellyproem50_08f9e0e68e48_em1_total_active_energy') ] | map('is_number') | min }}

Hope you have a smart idea… :wink:

Compare these 2, you have shifted everything after ‘# Load frontend themes from the themes folder’ to the right

Just because it works doesn’t mean it’s correct, sooner or later it will cause problems.

As Francis said, the indention is incorrect.

ok thnaks guys - but now please tell me which of the both is correct and which not…
I suspect the EM3 yaml is correct and the EM50 need to be changed - is is this what you mean?

Start by moving everything under ‘# Load frontend themes from the themes folder’ back , then restart HA

no!!

‘- sensor:’
is too much

here are both together :smiley:

template:
  - sensor:



      - name: "Power Total"
        unique_id: power_total
        state: >
          {{ states('sensor.shellypro3em63_2cbcbbb83640_phase_a_active_power')|float(0) +
             states('sensor.shellypro3em63_2cbcbbb83640_phase_b_active_power')|float(0) +
             states('sensor.shellypro3em63_2cbcbbb83640_phase_c_active_power')|float(0) }}
        unit_of_measurement: W
        device_class: power
        state_class: measurement
        availability: >
           {{
               [ states('sensor.shellypro3em63_2cbcbbb83640_phase_a_active_power'),
                 states('sensor.shellypro3em63_2cbcbbb83640_phase_b_active_power'),
                 states('sensor.shellypro3em63_2cbcbbb83640_phase_c_active_power') ] | map('is_number') | min }}

      - name: "Energy Total"
        unique_id: energy_total
        state: >
          {{ states('sensor.shellypro3em63_2cbcbbb83640_total_active_energy') }}
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        attributes:
          last_reset: "1970-01-01T00:00:00+00:00"
        availability: >
            {{ 
               [ states('sensor.shellypro3em63_2cbcbbb83640_total_active_energy') ] | map('is_number') | min }}
               

      - name: "Energieverbrauch Heizung"
        unique_id: Energieverbrauch Heizung
        state: >
          {{ states('sensor.shellyproem50_08f9e0e68e48_em1_power')|float(0) +
             states('sensor.shellyproem50_08f9e0e68e48_em0_power')|float(0) }}
        unit_of_measurement: W
        device_class: power
        state_class: measurement
        availability: >
           {{
               [ states('sensor.shellyproem50_08f9e0e68e48_em1_power'),
                 states('sensor.shellyproem50_08f9e0e68e48_em0_power') ] | map('is_number') | min }
      - name: "Energy Total Heizung"
        unique_id: Energy Total Heizung
        state: >
          {{ states('sensor.shellyproem50_08f9e0e68e48_em0_total_active_energy')|float(0) +
             states('sensor.shellyproem50_08f9e0e68e48_em1_total_active_energy')|float(0) }}
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        attributes:
          last_reset: "1970-01-01T00:00:00+00:00"
        availability: >
            {{ 
               [ states('sensor.shellyproem50_08f9e0e68e48_em0_total_active_energy'),
                 states('sensor.shellyproem50_08f9e0e68e48_em1_total_active_energy') ] | map('is_number') | min }}
1 Like

First of all many thanks for taking the effort to put all together into one yaml - realyl very much appreciated!
I copied and pasted it into a new test.yaml and restarted the machinery completly - however the entity “Energieverbrauch Heizung” and “Energy Total Heizung” still doesn’t turn up in the entlty list where I can chose from to include in a batch in my dahsboard.

Here also again a copy of the entire code of the “test.yaml”

# Loads default set of integrations. Do not remove.
default_config:

frontend:
 themes: !include_dir_merge_named themes
 # Load frontend themes from the themes folder

 automation: !include automations.yaml
 script: !include scripts.yaml
 scene: !include scenes.yaml
  
template:
  - sensor:

      - name: "Power Total"
        unique_id: power_total
        state: >
          {{ states('sensor.shellypro3em63_2cbcbbb83640_phase_a_active_power')|float(0) +
             states('sensor.shellypro3em63_2cbcbbb83640_phase_b_active_power')|float(0) +
             states('sensor.shellypro3em63_2cbcbbb83640_phase_c_active_power')|float(0) }}
        unit_of_measurement: W
        device_class: power
        state_class: measurement
        availability: >
           {{
               [ states('sensor.shellypro3em63_2cbcbbb83640_phase_a_active_power'),
                 states('sensor.shellypro3em63_2cbcbbb83640_phase_b_active_power'),
                 states('sensor.shellypro3em63_2cbcbbb83640_phase_c_active_power') ] | map('is_number') | min }}

      - name: "Energy Total"
        unique_id: energy_total
        state: >
          {{ states('sensor.shellypro3em63_2cbcbbb83640_total_active_energy') }}
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        attributes:
          last_reset: "1970-01-01T00:00:00+00:00"
        availability: >
            {{ 
               [ states('sensor.shellypro3em63_2cbcbbb83640_total_active_energy') ] | map('is_number') | min }}
               

      - name: "Energieverbrauch Heizung"
        unique_id: Energieverbrauch Heizung
        state: >
          {{ states('sensor.shellyproem50_08f9e0e68e48_em1_power')|float(0) +
             states('sensor.shellyproem50_08f9e0e68e48_em0_power')|float(0) }}
        unit_of_measurement: W
        device_class: power
        state_class: measurement
        availability: >
           {{
               [ states('sensor.shellyproem50_08f9e0e68e48_em1_power'),
                 states('sensor.shellyproem50_08f9e0e68e48_em0_power') ] | map('is_number') | min }
      - name: "Energy Total Heizung"
        unique_id: Energy Total Heizung
        state: >
          {{ states('sensor.shellyproem50_08f9e0e68e48_em0_total_active_energy')|float(0) +
             states('sensor.shellyproem50_08f9e0e68e48_em1_total_active_energy')|float(0) }}
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        attributes:
          last_reset: "1970-01-01T00:00:00+00:00"
        availability: >
            {{ 
               [ states('sensor.shellyproem50_08f9e0e68e48_em0_total_active_energy'),
                 states('sensor.shellyproem50_08f9e0e68e48_em1_total_active_energy') ] | map('is_number') | min }}

I am still struggling… :frowning:

How do you include the test.yaml file in the configuration? Is it just a new file? If so, HA will skip it - this file is not part of the configuration.

The configuration is in the configuration.yaml file.

This is wrong.

If you don’t know YAML why don’t you use helpers? Settings → Devices and services → Helpers → create helper → Template → template sensor

1 Like

Folks unfortunately have to leave now for a birthday party and won’t be back before Sunday some time…
But I will take a closer look asap. and this way sincere thanks for your extended help! (I might need to come back to it eventualyl but Bieniu’s hint might be pointing to the problem…!)
Will let you know the outcome!
Have a great weekend guys!
Rolf

no - its a different entity…
I know I need to be more precise in my naming convention… I will change this as well…
Cheers!