I got new curtain rails installed with motors.
The motors have a port on them for other devices to control them by connecting “dry contacts”.
I made a board in a box to install between the power socket and curtain motor, mains voltage goes into the box, mains voltage and a cable that plugs into the control port come out of the box.
It works super great.
I used a Wemos D1 Mini as the brains running ESPHome.
There are 3 relays, each to perform either the open, close, or stop actions.
There are three momentary switches which can be pressed to trigger the functions or of course they can be controlled with Home Assistant.
Here is the code I used on the D1.
switch:
- platform: gpio
id: relayOpen
interlock: &interlock_group [relayOpen, relayStop, relayClose]
pin: D5
- platform: template
name: "Tatami Curtains Close"
icon: "mdi:window-closed-variant"
turn_on_action:
- switch.turn_on: relayOpen
- delay: 500ms
- switch.turn_off: relayOpen
- platform: gpio
id: relayStop
interlock: *interlock_group
pin: D7
- platform: template
name: "Tatami Curtains Stop"
icon: "mdi:stop-circle-outline"
turn_on_action:
- switch.turn_on: relayStop
- delay: 500ms
- switch.turn_off: relayStop
- platform: gpio
id: relayClose
interlock: *interlock_group
pin: D6
- platform: template
name: "Tatami Curtains Open"
icon: "mdi:window-open-variant"
turn_on_action:
- switch.turn_on: relayClose
- delay: 500ms
- switch.turn_off: relayClose
binary_sensor:
- platform: gpio
pin:
number: D1
mode: INPUT_PULLUP
inverted: True
name: "Tatami Curtains Open Light"
on_press:
then:
- switch.turn_on: relayOpen
- delay: 500ms
- switch.turn_off: relayOpen
- platform: gpio
pin:
number: D2
mode: INPUT_PULLUP
inverted: True
name: "Tatami Curtains Close Light"
on_press:
then:
- switch.turn_on: relayClose
- delay: 500ms
- switch.turn_off: relayClose
- platform: gpio
pin:
number: D3
mode: INPUT_PULLUP
inverted: True
name: "Tatami Curtains Stop Light"
on_press:
then:
- switch.turn_on: relayStop
- delay: 500ms
- switch.turn_off: relayStop
I wanted to take this to the next level, instead of having 3 switches for 3 functions I used a cover template in Home Assistant to create a curtain entity and that works brilliantly with this code.
- platform: template
covers:
bedroom_curtains:
device_class: curtain
friendly_name: "Bedroom Curtains"
open_cover:
service: switch.turn_on
entity_id: switch.bedroom_curtains_open
close_cover:
service: switch.turn_on
entity_id: switch.bedroom_curtains_close
stop_cover:
service: switch.turn_on
entity_id: switch.bedroom_curtains_stop
I want to use the “position_template” function so I can tell the curtain how open or closed I want it to be and so my Home Assistant is able to read and display the current open/closed amount/percentage but I am having difficulty figuring this part out.
If anyone is able to help with this part I’d appreciate it and want to use this as a learning experience to enhance my skills as I go forward.
Thanks for any help offered.