Creating a perimeter alarm (pool fence) using a Sonof Basic unit by semiautomatix Jan 15, 2019 2 Uncategorised

Credit: Patrick Schutte

I wanted to create the ability to be aware when there could be someone or children close to my pool area. A rough sketch of the area in question is outlined below.

I set up the dual beam unit as shown above. With the distance to the Sonof basic unit being about 20+ metres, I could not simple connect directly to the Sonof unit which works with 3.3 volts. The easiest was to connect the relay from the perimeter sensor to 12 volts as well and drive a 12 volt relay mounted on the Sonof basic unit, this should ensure no false alarms or attenuation on the line.

For my purposes, I wanted to be able to activate and de-activate the alarm when the garden service was here or if we were going to be using the area.

Preparing the Sonof Basic unit

In the photo above, I have brought out all 5 wires for potential future expansion. I have glued the 12v relay onto the side for access as well. I am using pin 5(GPIO14) as my sensor which goes to the NO (Normally Open) pin of the relay, and Pin 4 (Ground) to the common of the relay.

The pinout details for the Sonof basic can be accessed at https://github.com/arendst/Sonoff-Tasmota/wiki/GPIO-Locations


Configuring the Sonof unit.

The Sonof unit is flashed with the Tasmota MQTT software, and configured as below:

By using switch 2 as the sensor, I can control when the unit gets switched on or off. If I had used switch 1, it would switch the unit on at the same time when activated.

You then go to the console, and enter switchmode2 4 this effectively sets the mode to toggle between on and off.

Configuring in Home Assistant.

In my sensors.yaml file, I added:


# MQTT binary sensors
- platform: mqtt
name: Pool Alarm
state_topic: "cmnd/poolfence/POWER2"
payload_on: “ON”
payload_off: “OFF”

In my switches.yaml file, I added:


- platform: mqtt
name: "Pool Siren"
command_topic: "cmnd/poolfence/power"
state_topic: "stat/poolfence/POWER"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true

I needed an indicator to define if the alarm is active or not, so I used the Boolean Input, this I added to my configuration.yaml:


# keep track of pool alarm state
input_boolean:
pool_alarm_active:
name: Activate pool alarm
initial: on
icon: mdi:gate

All we now have to do is define the automations to run it. I needed to be able to switch off the alarm on Thursdays between 7:30am and 10:00am for the garden service. I also have an automation so that the alarm will reset itself after 10 minutes after being activated. Finally, I added in the service to ensure that the alarm is active if we had an evening by the pool and I forgot to re-activate it.

Defining the automations.


#switch off alarm for the garden service.
- id: garden_service_arrive
alias: Garden Service Arrive
trigger:
- platform: time
at: '07:30:00'
condition:
- condition: time
weekday:
- thu
action:
entity_id: input_boolean.pool_alarm_active
service: input_boolean.turn_off

#switch on alarm after the garden service leaves.
- id: garden_service_leave
alias: Garden Service Leave
trigger:
- platform: time
at: '10:00:00'
condition:
- condition: time
weekday:
- thu
action:
entity_id: input_boolean.pool_alarm_active
service: input_boolean.turn_on

#switch on alarm if switch2 (GPIO14) is toggled.
- id: pool_alarm_triggered
alias: Pool Alarm Triggered
trigger:
platform: state
entity_id: sensor.pool_alarm
to: 'ON'
condition:
- condition: state
entity_id: input_boolean.pool_alarm_active
state: 'on'
action:
entity_id: switch.pool_siren
service: switch.turn_on

#switch off alarm and reset Switch2 state.
- id: pool_alarm_reset
alias: Pool Alarm Reset
trigger:
platform: state
entity_id: sensor.pool_alarm
to: 'ON'
for:
minutes: 10
action:
- service: switch.turn_off
entity_id: switch.pool_siren
- service: mqtt.publish
data:
topic: 'cmnd/poolfence/POWER2'
payload: 'OFF'
retain: 'true'

#switch on outside lights and reset pool alarm
- id: sunrise_routines_2
alias: Sunrise Outside Lights On
trigger:
- platform: time
at: '04:30:00'
action:
- service: light.turn_on
entity_id: light.outside_light
- service: input_boolean.turn_on
entity_id: input_boolean.pool_alarm_active

GUI Display

At this stage, I have not made my screens ‘pretty’ yet. On my GUI screen, I get the Switch2 displayed as Pool Alarm.

The Siren switch:

The Boolean input to activate and de-activate the alarm, as well as the various automations:

I hope this helps others to expand the use of their Sonof Basic units.

DISCLAIMER: Please ensure that your Sonof unit is disconnected from power before opening the unit up. There are dangerous voltages inside and if you do not know what you are doing, please get a qualified person to assist you.

Share with
COMMENTS
  • allen.bubb 15th Jan 2019 at 12:26 pm

    Hi . This looks Good.couple of questions.?
    1) How do you prevent sa pets trigering it ?
    2) what do you power with the sonoff Basic?

    Have a couple of places I can use this. thank you for sharing.

    Reply
    • semiautomatix 15th Jan 2019 at 2:31 pm

      Credit: Patrick Schutte

      I use an outdoor beam similar to this mounted about 80 – 90cm off the ground. I have it set to go off at a fast walk and it is high enough that the dog does not set it off.

      https://www.takealot.com/outdoor-du…zu823hAE6YAoyGujQq8aAmpxEALw_wcB&gclsrc=aw.ds

      I had an old 12v power supply from a camera that I re-purposed for a siren that I also had lying around.

      I suppose that I could have used a Sonoff SV instead of the Basic.

      Reply

POST YOUR COMMENTS


you may like
New Sonoff T1 EU 3 Gangs is Coming by semiautomatix Jan 25, 2019 7

Credit: Linda Chow It’s been a long time since Sonoff has released it 1 and 2 gangs T1 series. Now we are going to launch a 3 gang T1(EU) to make the whole T1 series complete. This time, however, we decided to make an adjustment to differentiate it from the T1 series. We didn’t ..

READ MORE