I have 2 sonoff s20 smart plugs flashed with tasmota 6.7.1.
I want set a timer for each plug such that at a set time or times, each smart plug is switched on for a set time. I have tried the automation editor but I haven’t a clue.
Any help welcome.
Here an example of code I use to turn on my water heater which is connected to a TP-Link smart outlet. The code uses automation to turn on and turn off a switch at a time you can enter into a time box in the ui. It also provides a separate status ui for the switch and time remaining. The status ui also lets you manually start the switch as well.
Add input_datetime, time and timer to configuration.yaml
input_datetime:
pump_morning_on:
has_date: false
has_time: true
sensor:
- platform: time_date
display_options:
- 'time'
timer:
pump:
duration: '00:30:00'
Then automation to turn it on and turn off automatically when timer is done
# Pump Automations
- alias: 'Pump Morning On'
trigger:
platform: template
value_template: >
{{ states('sensor.time')
== (states.input_datetime.pump_morning_on.attributes.timestamp
| int | timestamp_custom('%H:%M', False)) }}
action:
- service: script.pump_timer
- alias: 'Pump Timeout'
trigger:
platform: event
event_type: timer.finished
event_data:
entity_id: timer.pump
action:
- service: switch.turn_off
entity_id: switch.pump
Add a small script. Use a script so it can be started from an automation or manually from the ui.
# Pump Scripts
pump_timer:
alias: 'Pump Timer'
sequence:
- condition: state
entity_id: timer.pump
state: 'idle'
- service: switch.turn_on
entity_id: switch.pump
- service: timer.start
entity_id: timer.pump
Add following to ui entities
# Pump status
- type: entities
title: Water Heater
show_header_toggle: false
entities:
- type: call-service
name: Pump
icon: mdi:water-pump
action_name: Start
service: script.turn_on
service_data:
entity_id: script.pump_timer
- entity: timer.pump
name: Time remaining
- type: section
label: '(Schedule 7:00am-7:30am daily)'
# Settings for time input
- type: entities
title: Switches
show_header_toggle: false
entities:
- entity: input_datetime.pump_morning_on
name: Pump on at