I haven’t been using Home Assistant for very long and now I’m trying to build the following:
I have a smart mirror with a Raspberry Pi in the hallway. It is connected to a TP Wi-Fi socket. I would now like to switch the mirror on and off via Home Assistant.
To switch it on, simply turn on the TP Wi-Fi socket. Then the Raspberry Pi and the screen turn on.
To switch it off, turn off the Raspberry Pi, wait for 1 minute, and then turn off the TP Wi-Fi socket.
A simple ping is sufficient to determine the status of the mirror.
The above should give you the basic functionality you’re asking for. However, it does have one flaw: i.e., if switch.flur_spiegel is turned off, and then turned back on before the turn_off sequence completes, it could leave things in an undesirable state.
That can be addressed by creating a script, and then using that script in the template switch.
script:
# This creates script.spiegel_power
spiegel_power:
alias: Spiegel Power
description: Turn Flur Spiegel on or off
fields:
value:
name: Value
description: Turn power on or off
example: "off"
required: true
default: "on"
selector:
select:
options:
- "on"
- "off"
mode: queued
sequence:
- if: "{{ value == 'on' }}"
then:
- service: switch.turn_on
entity_id: switch.spiegel
else:
- service: shell_command.spiegel_pi_shutdown
- delay:
minutes: 1
- service: switch.turn_off
entity_id: switch.spiegel
If the script is called to turn the power off, and then it is called again to turn the power on, but before the turn off sequence has completed, it will complete the turn off, and then do the turn on sequence. This is due to the chosen script mode, which is queued.