question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Light switch is unavailable if made from switch template

See original GitHub issue

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

  • Home Assistant Core release with the issue: 0.117.5
  • Last working Home Assistant Core release (if known): 0.116
  • Operating environment (OS/Container/Supervised/Core): Virtualenv on Raspberry Pi
  • Integration causing this issue: Light Switch
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/light.switch/

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

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
frenckcommented, Nov 8, 2020

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?

0reactions
OleksandrBerchenkocommented, Jul 15, 2022

Yes, this is still actual.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[SOLVED]Template switch that can be on/off/unavailable?
Hey guys, I ve been trying to create a template switch that would also show me if the actual switch is unavailable apart...
Read more >
Light Switch Not Working in 2023? Here's How to Troubleshoot It
So the first thing to check is the breaker in your home's electrical panel. If that's not the case, you have other issues....
Read more >
Troubleshoot Switch Port and Interface Problems - Cisco
If the link light for the port does not come on, you can consider these ... For example, you have a switch that...
Read more >
Wemo Smart Light Switch 3-Way, WLS0403 Frequently Asked ...
What are the wires of the Wemo Light Switch made of? ... It may be dangerous or illegal to install if the neutral...
Read more >
Problems with Download Codes (Software, DLC, and Themes)
Applies to: Nintendo Switch Family, Nintendo Switch, Nintendo Switch Lite, Nintendo Switch ... A game or theme download code from a retailer, prepaid...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found