So for my next example, I actually use a door/window sensor to turn on a light. In my real-world example, the door sensor turns on a Z-Wave light, but I’ll adopt the example for a RPI-RF switch instead.
Use Pilight to receive the codes as stated above and create 2 automations, one for the door opening and the other for the door closing.
automations/pilight_door1_opening.yaml
alias: "pilight_door1_opened"
trigger:
platform: event
event_type: pilight_received
event_data:
protocol: ev1527
uuid: 0000-b8-27-eb-4ffabe
unitcode: 355554
state: opened
action:
- service: homeassistant.turn_on
entity_id: input_boolean.closet_door
automations/pilight_door1_closed.yaml
alias: "pilight_door1_closed"
trigger:
platform: event
event_type: pilight_received
event_data:
protocol: ev1527
uuid: 0000-b8-27-eb-4ffabe
unitcode: 879842
state: opened
action:
- service: homeassistant.turn_off
entity_id: input_boolean.closet_door
The above Pilight automations trigger a fake switch (input_boolean) in HASS. Now we need to create this input_boolean switch. We use this fake switch in HASS so you can track the status of the door:
input_boolean:
closet_door:
name: Closet Door
initial: off
icon: mdi:glassdoor
Now, we need to create automations that actually send the RPI-RF codes to turn on/off the light whenever the input_boolean switch is turned on (opened) and off (closed):
automations/closet_door_opened.yaml
alias: "closet_door_opened"
trigger:
platform: state
entity_id: input_boolean.closet_door
from: 'off'
to: 'on'
action:
- service: homeassistant.turn_on
entity_id: switch.rpirf_closet_light
automations/closet_door_closed.yaml
alias: "closet_door_closed"
trigger:
platform: state
entity_id: input_boolean.closet_door
from: 'on'
to: 'off'
action:
- service: homeassistant.turn_off
entity_id: switch.rpirf_closet_light
Now, create the RPI-RF switch in HASS:
rpirf_closet_light:
#Closet Light
code_off: 28890
code_on: 28881
protocol: 1
pulselength: 200
signal_repetitions: 15
Save everything and restart HASS. You should now have a light that turns on when you open the door, and off when you close the door.