1. intro
this tutorial will show u how to configure homeassistant 2 use a doorswitch such as:
purpose is to react asap in case of an event to take an action such as logging to a file.
2. shell command
mkdir -p /config/custom_components/dsw/{bin,etc,log,tmp}
vi /config/configuration.yaml
///
shell_command: !include_dir_merge_named shell_commands/
vi /config/custom_components/dsw/etc/dsw.yaml
#
dsw: /config/custom_components/dsw/bin/dsw "{{ device }}" "{{ state }}"
rm -fv /config/shell_commands/dsw.yaml
ln -sv /config/custom_components/dsw/etc/dsw.yaml /config/shell_commands/
vi /config/custom_components/dsw/bin/dsw
#!/bin/sh
logfile="/config/custom_components/dsw/log/$(date '+%Y%m%d').log"
echo "$(date '+%T'): $1 - $2" >> ${logfile}
exit 0
chmod +x /config/custom_components/dsw/bin/dsw
systemctl restart homeassistant.service
3. automation
cat config/automations.yaml
- id: '1715891945600'
alias: dsw_on
description: ''
trigger:
- type: opened
platform: device
device_id: ad0cd12631cf97b31244530d75148386
entity_id: 8d0465579db65a68bec6fda11d443855
domain: binary_sensor
condition: []
action:
- service: shell_command.dsw
data:
device: dsw003
state: open
mode: single