Reading power consumption from a MyStrom smart plug

Hello

I have a MyStrom smart plug from which I want to read out the current power consumption. As the example shows I have added this to my configuration:

switch:
  - platform: mystrom
    host: 192.168.8.6
    name: ender

sensor:
  - platform: template
    sensors:
      power:
        friendly_name: "Stromverbrauch Ender"
        unit_of_measurement: "W"
        value_template: "{{ state_attr('switch.ender', 'current_power_w') }}"

I can see the sensor on the dashboard, but I don’t get any values. Obviously something seems to be wrong, but I can’t figure out what. Should current_power_w be the name of the field returned by the API?

Thank you for any help

does anybody maybe have a hint for me?

After updating to the latest version of Home Assistant, I had the same issue. I found a workaround by using a rest sensor:

sensor:
  - platform: rest
    name: "Washing Power"
    resource: http://192.168.1.26/report
    method: GET
    unit_of_measurement: W
    device_class: energy
    state_class: measurement
    value_template: "{{ value_json.power }}"
    scan_interval: 10

This solution works for me. But I think a proper fix is needed.

After a recent HA update the power consumption is also not displayed for me anymore. I am currently running " Home Assistant 2022.4.6".

Before everything was fine … :frowning:

1 Like

Though this certainly needs to be handled by whoever maintains the integration code, could this just be an issue with the deprecation (and recent final removal) of device_state_attributes?

The Genius lyrics integration had a similar issue: just required replacing the above with extra_state_attributes.

…any updates on this?

Seems dead :frowning:
I’m still using the above mentioned workaround using a REST sensor.

Any updates?

Well, it seems that there will be no update for this. Se here: Deprecate current_power_w and today_energy_kwh switch properties and here Deprecate Switch entity properties

It was on purpose to separate the Power Consumption from the Switch. From now on, the Power Consumption will not be a property of the switch anymore; you will have to define it as a sensor.

This is how I have defined it:

sensor:
  - platform: rest
    name: "Washing machine power consumption"
    resource: http://172.16.0.52/report
    method: GET
    unit_of_measurement: W
    device_class: energy
    state_class: measurement
    value_template: "{{ value_json.power }}"
    scan_interval: 10

Unfortunately this is not so reliable when if your wifi network is unstable. From time to time it will result in failed reading because timeout or other network related reasons, an that can cause automation re-trigger because of a change in value.

Example:
you have value 0 → you have a timeout(value undefined) → a good reading again with value 0. Since the value is “0” again, the automation will re-trigger if that’s your trigger. Having 0.1 instead 0 as trigger value will not help either.

I would like to see the mystrom integration for switch sensors as they did it when the power was a switch property… that was more reliable than the Rest sensor

Just a quick comment, you need to use device_class: power instead of device_class: energy

Also, to include in the Energy dashboard, you need to add an integrator like in this comment .