In my post about Farm CCTV I discussed adding lighting controls into the video feeds to switch on the lights over calving pens, one issue with turning on the lights remotely is forgetting to turn them off. At the heart of my remote lighting controls is a Sonoff 4CH Pro, I’ve used 3 channels for lighting and the other one controls the electric fence unit.
I’ve created 2 automations with configurable timers. The first timer will switch back on the electric fence should I turn it off remotely after a set period of time so if I forget to turn back on the fence it will switch itself back on. The second timer will do the opposite and will switch off any of the lights after a set period of time should I forget to turn them off.
Code below is added to automations.yaml
- id: '1612767885314'
alias: Electric Fence Watch guard
description: ''
trigger:
- platform: state
entity_id: switch.sonoff_1000xxxxxx_4
from: 'on'
to: 'off'
for:
minutes: '{{ states(''input_number.fence_timer'')|int }}'
action:
- service: switch.turn_on
data: {}
entity_id: switch.sonoff_1000xxxxxx_4
Code language: JavaScript (javascript)
- id: '1612809026301'
alias: Auto shed Lights Off
description: ''
trigger:
- platform: state
entity_id: switch.sonoff_1000xxxxxx_1, switch.sonoff_1000xxxxxx_2, switch.sonoff_1000xxxxxx_3
from: 'off'
to: 'on'
for:
minutes: '{{ states(''input_number.shed_light_timer'')|int }}'
action:
- service: switch.turn_off
data_template:
entity_id: "{{ trigger.entity_id }}"
Code language: JavaScript (javascript)
Code below is added to configuration.yaml
input_number:
fence_timer:
name: Fence Timer
min: 1
max: 60
step: 1
mode: box
icon: mdi:timer-sand
shed_light_timer:
name: Shed Light Timer
min: 1
max: 60
step: 1
mode: box
icon: mdi:timer-sand
Code language: CSS (css)
I’ve used a Sonoff smart switch, but any smart switch that can be integrated with Home Assistant will work just the same. A third party integration like Sonoff LAN is required to integrate Sonoff devices with Home Assistant. Alternatively they can be integrated using custom firmware such as Tasmota.
Facebook Comments