Does anyone have any ideas on how we could emulate a child lock on a smart plug? Something in the lines of on_double_click ‘deactivate’ the switch with delay until a new double click. Or a long click. I have the automation in my head, but can’t emulate the ‘temporary deactivation’ of the switch itself. There is no such action in the documentation. Thanks in advance.
Anyone has any ideas?
So the double (or long) click on the button (binary_sensor) should deactivate the ability to toggle the relay (switch) - correct?
As an idea just add a template switch (child lock ) to your esphome node and use interlock
function together with the switch you have already.
Just today i’d started looking at a template switch! Thanks a lot. But I was thinking of an automation on the node itself with conditions if the 'child’s’switch is on, deactivate the normal one. Does the interlock function also work with a template switch? I went through the documentation and saw that it’s related to a normal gpio switch.
That should also be no problem and still easy while might require just a little bit more logic as you will (ether way) still need to “save” the child lock state somewhere (for example in a template binary sensor or global
).
I would very much expect/hope that
But you are right in that regard - maybe (hopefully) the docs just missing some info.
Very weird that the switch core
doesn’t include any interlock
Guess one just needs to try if there a limited gpio switch
only
Yes, I’ve seen these docs too. I will try it. But I’m afraid interlocking is only for gpio switches. Interlock is not mentioned neither in switch core nor in template switches.
What do you mean when you say I have to 'save 'the state somewhere?
Like the esphome node needs to know if the the the “child lock” is enabled ("on) or not ("off) - that’s why I suggested a template switch in the very beginning.
Still there are many roads you can follow like using a global variable or a template binary sensor.
Do that. Just go ahead and try (trial & error is sometimes needed ). And if you are stuck just paste your yaml
here and describe whats not working like intended so it can get fixed
Ok, since I wasn’t able to find code for a child lock (strange), I’m now sharing my own for the community. As I was writing this up, I came upon a couple of automations I had to devise, in order to completely emulate a factory child’s lock. I’m not completely familiar with the interlock
function, so I followed the path of automations and template switch
. But I’m going to try interlock as soon as I find time. The interesting snippets follow:
#the physical button
binary_sensor:
- platform: gpio
pin:
number: GPIO3
inverted: True
name: $friendly_name
on_multi_click:
#normal on/off operation with led flashing if child lock activated:
- timing:
- ON for at most 1s
then:
if:
condition:
switch.is_off: plug_lock
then:
- switch.toggle: relay
else:
- repeat:
count: 3
then:
- light.turn_on:
id: error_led
brightness: 100%
- delay: 0.5s
- light.turn_off: error_led
- delay: 0.5s
#child lock operation with led notification:
- timing:
- ON for at least 3s
then:
- switch.toggle: plug_lock
- light.turn_on:
id: error_led
brightness: 100%
- delay: 0.7s
- light.turn_off: error_led
switch:
#led
- platform: gpio
id: led
pin:
number: GPIO13
inverted: True
#the actual relay
- platform: gpio
name: $friendly_name
pin: GPIO14
id: relay
restore_mode: $plug_restore_mode
on_turn_on:
- switch.turn_on: led
on_turn_off:
- switch.turn_off: led
icon: mdi:power
#the emulated child lock switch
- platform: template
name: $friendly_name child's lock
id: plug_lock
restore_state: yes
optimistic: true
#error led output
output:
- platform: esp8266_pwm
id: blue_led
pin:
number: GPIO1
inverted: true
#error led light
light:
- platform: monochromatic
id: error_led
internal: True
output: blue_led
default_transition_length: 100ms
As you can see I’ve implemented a couple of extras, namely: a) When child lock is enabled and the button pressed for a normal operation, a led flashes 3 times in order to indicate active child lock. Very interesting to learn about the repeat
function. b) When the button is pressed in order to activate child lock, as soon as the designated time passes a led flashes once in order to indicate that child lock has been activated (this is very useful, because otherwise the user doesn’t know if child lock has indeed been activated).
I opted for a template switch
instead of a template binary sensor
, because it doesn’t hurt to have the option to toggle the child lock from the frontend (with a binary sensor that would not be possible).
I’ve tried the above code with a Gosund SP1 plug, so don’t copy and paste blindly the code, you have to adjust the pin settings and/or various other options for an other plug.
Edit: @orange-assistant Unfortunately no, interlock
is not supported for template switches: Interlock for all switches · Issue #1709 · esphome/feature-requests · GitHub