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
72.44k stars 30.32k forks source link

Light switch is unavailable if made from switch template #42984

Open OleksandrBerchenko opened 3 years ago

OleksandrBerchenko commented 3 years ago

The problem

After HA restart, a light switch made from a switch template remains unavailable until the switch changed its state. This bug is introduced in 0.117, earlier it worked as expected.

Environment

Problem-relevant configuration.yaml

switch:
  - platform: template
    switches:
      readinglamp_wrapper:
        value_template: "{{ states.switch.readinglamp.state == 'on' }}"
        availability_template: "{{ states.switch.readinglamp != None and states.switch.readinglamp.state != 'unavailable' and states.binary_sensor.power.state == 'on' }}"
        turn_on:
          service: switch.turn_on
          entity_id: switch.readinglamp
        turn_off:
          service: switch.turn_off
          entity_id: switch.readinglamp

light:
  - platform: switch
    name: readinglamp
    entity_id: switch.readinglamp_wrapper

switch.readinglamp comes from Xiaomi Gateway (Aqara) UI integration.

Traceback/Error logs

2020-11-08 20:58:15 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=switch.readinglamp_wrapper, old_state=None, new_state=<state switch.readinglamp_wrapper=off; friendly_name=readinglamp wrapper @ 2020-11-08T20:58:15.768398+02:00>>
...
2020-11-08 20:58:15 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=light.readinglamp, old_state=None, new_state=<state light.readinglamp=unavailable; friendly_name=readinglamp, supported_features=0 @ 2020-11-08T20:58:15.790523+02:00>>
...
2020-11-08 20:58:20 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=switch.readinglamp, old_state=None, new_state=<state switch.readinglamp=off; in_use=0, load_power=0.0, power_consumed=537.0, voltage=3.6, battery_level=100.0, friendly_name=readinglamp, icon=mdi:power-plug @ 2020-11-08T20:58:20.816473+02:00>>

Additional information

N/A

frenck commented 3 years ago

Maybe a weird question (and probably a bit off-topic as well). But... euhm... why are you using a switch template and use the light switch to convert it into a light? Why not use a light template directly?

probot-home-assistant[bot] commented 3 years ago

light documentation light source (message by IssueLinks)

OleksandrBerchenko commented 3 years ago

@frenck To have a clean code :) Please note, I have a lot of similar switch templates (which handle a power outage) and not of them are used for lights. Until this bug is fixed, I have already converted all of them into light templates.

Thanks!

dgomes commented 3 years ago

I think this is the same issue as https://github.com/home-assistant/core/issues/43457

github-actions[bot] commented 3 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 has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

OleksandrBerchenko commented 3 years ago

Yes, this is still actual.

RolandvanOers commented 3 years ago

Same problem here, some lights are unavailable but the original switch is.

github-actions[bot] commented 3 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 has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

OleksandrBerchenko commented 3 years ago

Yes, this is still actual.

jprintz commented 3 years ago

The same issue occurs for me when just turning a switch into a light using the Light Switch platform. In other words, this occurs even when not using switch templates, it seems to affect any kind of switch that is turned into a Light Switch. A restart of HA resets the light switches so that they are shown as available again.

RolandvanOers commented 3 years ago

Problem is still the same indeed, anything turned into a light switch is unavailable after 1 or 2 uses

github-actions[bot] commented 3 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 has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

OleksandrBerchenko commented 3 years ago

Yes, this is still actual.

github-actions[bot] commented 2 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 has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

OleksandrBerchenko commented 2 years ago

Yes, this is still actual.

ronytomen commented 2 years ago

Can those having problems post the template light configuration in YAML?

Also, the light entities that are used within the template light or light switch, which integration/component ultimately supports those light entities?

github-actions[bot] commented 2 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 has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

OleksandrBerchenko commented 2 years ago

Yes, this is still actual.

issue-triage-workflows[bot] commented 1 year 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 has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

OleksandrBerchenko commented 1 year ago

Yes, this is still actual.

issue-triage-workflows[bot] commented 1 year 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 has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

OleksandrBerchenko commented 1 year ago

Yes, this is still actual.

issue-triage-workflows[bot] commented 1 year 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 has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

OleksandrBerchenko commented 1 year ago

Yes, this is still actual.

issue-triage-workflows[bot] commented 1 year 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 has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

OleksandrBerchenko commented 1 year ago

Yes, this is still actual.

issue-triage-workflows[bot] commented 9 months 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 has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

OleksandrBerchenko commented 9 months ago

Yes, this is still actual.

issue-triage-workflows[bot] commented 6 months 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 has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

OleksandrBerchenko commented 6 months ago

Yes, this is still actual.

issue-triage-workflows[bot] commented 3 months 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 has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

OleksandrBerchenko commented 3 months ago

Yes, this is still actual.

issue-triage-workflows[bot] commented 3 days 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 has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

OleksandrBerchenko commented 3 days ago

Yes, this is still actual.