I’m new to HA. I’ve been able to add my sonoff switches and try some simple automations.
What i’d like to create now is an automation that makes the next steps:
Save the state of a set of (let’s say three) sonoff switches in variables.
Switch off all of them.
Wait for a defined period of time.
Restore initial state of the sonoff switches.
I’d like to use a remote RF linked to a sonoff RF bridge as trigger, but from what I’ve read I have to hack with Tasmota (please, correct me if this is not necessary). So, I’d use another trigger system, as by now, I don’t want to change anything in hardware/firmware.
Thank you in advance. Any help will be welcome.
Miguel
Yeah scenes were just an easy way to set device states without having to know the services required until that particular ability was introduced. It’s one of the best enhancements and makes scenes a really powerful tool.
If you are not seeing any service like scene.create , you would need to enable it by adding scene: !include scenes.yaml to configuration and then create scenes.yaml in config folder.
- id: '1611335123017'
alias: heaters off
description: ''
mode: single
trigger:
- platform: state
entity_id: switch.sonoff_1000caee2e_4
from: 'off'
to: 'on'
condition: []
action:
- service: scene.create
data:
scene_id: before
snapshot_entities: 'switch.sonoff_1000caee2e_1,switch.sonoff_1000caee2e_2,switch.sonoff_1000caee2e_3'
- service: switch.turn_off
data: {}
entity_id: 'switch.sonoff_1000caee2e_1,switch.sonoff_1000caee2e_2,switch.sonoff_1000caee2e_3'
- delay: '00:01:00'
- service: scene.turn_on
data: {}
entity_id: scene.before
But I get the next error:
2021-01-22 18:26:38 ERROR (SyncWorker_0) [homeassistant.util.yaml.loader] while parsing a block collection
in "/config/automations.yaml", line 12, column 4
expected <block end>, but found '<block mapping start>'
in "/config/automations.yaml", line 13, column 5
2021-01-22 18:26:38 ERROR (MainThread) [homeassistant.bootstrap] Failed to parse configuration.yaml: while parsing a block collection
in "/config/automations.yaml", line 12, column 4
expected <block end>, but found '<block mapping start>'
in "/config/automations.yaml", line 13, column 5. Activating safe mode
Going on with the automation in this thread, I have a little issue that maybe has no easy solution. In any case, I ask just in case…
Imagine that while the delay is waiting after the state is saved in the ‘before’ scene, I have another automation that based on a scheduler (really I use schedule cards), the state of one of the switches changes to another desired state. When the delay finally finishes, the previous state of the switch is set. As a result the final state is not the desired one.
To put you in situation, I think it’s better to describe the scenario I have:
I have several electrical heaters in my flat. I schedule their use to take profit of the cheaper electricity periods of the day while avoiding to surpass my hired power limit.
Sometimes I have to use some appliances, like the microwave, and of course I want to use it at any time. So, the idea behind this thread was to create an automation that saves the state of the heaters, switch them off for a period of time (maybe 3 minutes in the case of the microwave), and after that period, recover the state of the heaters.
As I said the hole in this approach is what I described above.
We can skip the scheduled operation of the heater while this automation is in progress. This can be done by creating an input_boolean and adding the action to switch it on at the start of this automation and at the last turning it off. In the scheduler card you can put a condition when to start the heater. I dont know how useful this can be.
But if you have your scheduling operations done with automations in HA, we have the option to delay the scheduled operations till this particular operation has been completed. We just needed to use the choose action type.
Even with schedule card we can delay the scheduled operations but it would be lengthy if you have many schedules. In a day how many times you have scheduled operations?
In the meantime, I’ve tried this code and it seems to work:
- id: '1611593229900'
alias: test switch off heater 1
description: ''
trigger:
- platform: time
at: '1:14'
- platform: time
at: '1:15'
- platform: time
at: '1:16'
condition: []
action:
- wait_template: '{{ is_state(''input_boolean.microondas_boolean'',''off'') }}'
timeout: 00:05:00
continue_on_timeout: true
- service: switch.turn_off
data: {}
entity_id: switch.sonoff_1000caee2e_4
mode: single
I don’t know if I’m missing anything.
Could I use any of the approaches with scheduler-cards? The thinf is that sometimes I have to change the times of the schedule, or activate/deactivate some intervals, so it’s much more convenient schedurler-cards than plain automations.