I wanted to be able to manually trigger a recording on my Surveillance Station, you can use I/O devices such as the Advantech ADAM-6050. But using I/O devices uses up a device (Camera) licence. So I wanted an alternative option.
Luckily there is the “Action Rule” which allows you to trigger a recording using the API.
I am using a Sonoff RF Bridge flashed with Tasmota Firmware and a Kerui D026 RF Door / Window Switch in this example.
First Step is to create an Action Rule
Click on Add first.
You will want to give it a Name, select triggered and decide if you want the recording Interruptible or not.
Select “External device” under “Event Source” You can have up to 10 External Events.
Then click on “Get Command”
Copy and paste the block of code somewhere safe for now such as a text editor. You will need to change {account} and {password} to your username and password details.
Select which Camera you want to record, select “Start action rule recording” under “Action” and select how long you want to record for when triggered under “Duration”
On the next page select the trigger schedule. I left it at the default 24/7. But you could select during the night or when you are at work etc.
Next step is to log into your SonoffRF Bridge with Tasmota Firmware installed and go to the console page.
You want to look for the Data it gives for when the door / window is open.
In my case the Data ending EE is for the device open and E7 is for when it’s closed.
On this Kerui D026 there is also a third code ending EB stating it’s being tampered with (removed from the object it’s attached to) Note the full Data Code down for open ie 2xxxEE.
Now it’s time to add code into Home Assistant.
You will need to setup MQTT first to communicate to the RF Bridge running Tasmota Firmware.
Then add the following code bits you saved from earlier.
configuration.yaml
rest_command:
gate_record:
url: 'https://ipaddress:5001/webapi/entry.cgi?api=SYNO.SurveillanceStation.ExternalEvent&method="Trigger"&version=1&eventId=1&eventName="This is external event1"&account="username"&password="password"'
automations.yaml
- alias: RecordGateOpen
trigger:
platform: mqtt
topic: tele/sonoffBridge/RESULT
condition:
condition: template
value_template: '{{ trigger.payload_json.RfReceived.Data == "2XXXEE" }}'
action:
- service: rest_command.gate_record
Now hopefully when your Door / Window goes into open state it will trigger Surveillance Station to record on the Camera you selected. You can tell triggered recording in Surveillance Station as they have a pinky purple colour box to them instead of green.