Hello to all,
I’m new to this great community and would like to share a workaround for the eWelink integration bug:
When you try to create an automation with the eWelink Sonoff smart switch, eg. “Action:” call service → switch.toogle → entity (switch), the automation will not work, or rather it will not be able to find the switch. In the Home Assistant Log you can read this " Unable to find referenced entities switch.XXXXXX".The cause of this error is an integration bug and you can read the developer’s POV on their github…
How to? You can call a simple script as a service in your automation:
Copy the script code into your scripts.yaml:
'1234567890123': #edit this key
alias: Toggle eWelink
sequence:
- choose:
- conditions:
- condition: state
entity_id: &device switch.XXXXXXXXX #change the switch ID (find it in state tab under developer tools)
state: 'on'
sequence:
- service: switch.turn_off
entity_id: *device
- conditions:
- condition: state
entity_id: *device
state: 'off'
sequence:
- service: switch.turn_on
entity_id: *device
and in action of your automation.yaml:
action:
- service: script.turn_on
target:
entity_id: script.1234567890123 # copy here the script key
mode: single
WARNING: Do not modify the script with the UI editor, because HA reformats the code and causes the script stop
I hope this can help someone…
Notes:
If the problem has already been discussed and solved, please apologize in advance for the uselessness of my post.
I’m not english, sorry for my bad grammar.
123: #edit this key
alias: Toggle eWelink
sequence:
- choose:
- conditions:
- condition: state
entity_id: &device switch.XXXXXXXX_1 #change the switch ID (find it in state tab under developer tools)
state: 'on'
sequence:
- service: switch.turn_off
entity_id: *device
- conditions:
- condition: state
entity_id: *device
state: 'off'
sequence:
- service: switch.turn_on
entity_id: *device
I’ve basically copied your code word for word (except my switch ID), but when I try run the script I get “Failed to call service script/turn_on. Service not found”
To solve Failed to call service xxxxx/xxxxxxx. Service not found. issue, use File editor to edit configuration.yaml. Append the following info to end of file:
Initially I solved the problem following what you said.
However, now I found that switch.toggle doesn’t work, but switch.turn_on and switch.turn_off do.
Then you can use this command directly.