home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.38k stars 30.64k forks source link

myStrom switch does not report current_power_w when it's zero #24780

Closed messismore closed 5 years ago

messismore commented 5 years ago

Home Assistant release with the issue:

94.4

Last working Home Assistant release (if known):

Operating environment (Hass.io/Docker/Windows/etc.):

Hass.io

Component/platform:

myStrom switch

Description of problem:

image

The switch's current_power_wattribute will not update when power consumption drops to zero but instead sticks to the last reported value. (It seems like Hass is no longer reporting it? When I query the state of the switch with the hass cli the attribute is no longer listed)

The component relies on https://github.com/fabaff/python-mystrom which correctly reports the switch's consumption.

Is this a problem with how Home Assistant deals with attributes? I noticed that when I change mystrom/switch.py to always return current_power_w = 0 the attribute does not show up in Home Assistant either…

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant): Switch

- platform: mystrom
  name: "mystrom_switch"
  host: 192.168.0.32

Sensor

- platform: template
  sensors:
    mystrom_switch_power:
      unit_of_measurement: "W"
      value_template: "{{ states.switch.mystrom_switch.attributes.current_power_w }}"

Traceback (if applicable):

Additional information:

ghost commented 5 years ago

Hey there @fabaff, mind taking a look at this issue as its been labeled with a integration (mystrom) you are listed as a codeowner for? Thanks!

This is a automatic comment generated by codeowners-mention to help ensure issues and pull requests are seen by the right people.

stale[bot] commented 5 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

mcdmx commented 4 years ago

Same here... My quick and dirty workaround was to always add 0.01 to the result returned by components/switch/mystrom.py, (current_power_w).

dezuber commented 4 years ago

Same here... My quick and dirty workaround was to always add 0.01 to the result returned by components/switch/mystrom.py, (current_power_w).

hey would you mind explaining how to add that? i'm having the same issue as i'm trying to use an automation based on th read-out.

matoxp commented 4 years ago

hey would you mind explaining how to add that? i'm having the same issue as i'm trying to use an automation based on th read-out.

Depending on the version of home-assistant you're running, either edit components/switch/mystrom.py or components/mystrom/switch.py, look for def current_power_w(self):, change the return statement two lines below to return round(self.data['power'] + 0.01, 2) and finally restart home-assistant.

dezuber commented 4 years ago

Depending on the version of home-assistant you're running, either edit components/switch/mystrom.py or components/mystrom/switch.py, look for def current_power_w(self):, change the return statement two lines below to return round(self.data['power'] + 0.01, 2) and finally restart home-assistant.

Hey thanks for getting back at me. I‘m running hass.io on a raspberry 4 and am using the standart integration (adding it to config.yaml). I ssh‘d as root but can’t find either of those folders, not even the components one.

messismore commented 4 years ago

@dezuber As far as I know, components in <config dir>/custom_components overwrite the built in ones, but I can't find it in the documentation right now.

You can get the original file here.

dezuber commented 4 years ago

@messismore thanks for your reply. just created the folders \hassio\config\custom_components\mystrom and added the file you posted. doesn't seem to work...

messismore commented 4 years ago

@dezuber I just tried it and it seems to work. Did you make the change suggested by @matoxp?