wcavanagh
(Will Cavanagh)
April 30, 2024, 8:39am
1
So I have a ESP-01 Relay Board with the below code working. However I need to change this so that the switch is momentry for 800ms then turns off again. Any ideas?
uart:
baud_rate: 9600
tx_pin: GPIO1
switch:
- platform: template
name: "WIFI Relais EIN/AUS"
turn_on_action:
- uart.write: [0xA0, 0x01, 0x01, 0xA2]
turn_off_action:
- uart.write: [0xA0, 0x01, 0x00, 0xA1]
optimistic: true
I found this code online but no idea how to get it into the above.
# Example configuration entry
switch:
- platform: gpio
pin: 25
id: relay
name: "Gate Remote"
icon: "mdi:gate"
on_turn_on:
- delay: 500ms
- switch.turn_off: relay
Please can anyoen help at all.
wcavanagh
(Will Cavanagh)
April 30, 2024, 8:54am
3
Thank you, yes this is where i got the 2nd bot of code from.
However im struggling how to edit my first code to do this.
nickrout
(Nick Rout)
April 30, 2024, 8:58am
4
So you need to change 500 to 800.
tom_l
April 30, 2024, 9:00am
5
You could just do this:
switch:
- platform: template
name: "WIFI Relais EIN/AUS"
turn_on_action:
- uart.write: [0xA0, 0x01, 0x01, 0xA2]
- delay: 800ms
- uart.write: [0xA0, 0x01, 0x00, 0xA1]
turn_off_action:
- uart.write: [0xA0, 0x01, 0x00, 0xA1]
optimistic: true
wcavanagh
(Will Cavanagh)
April 30, 2024, 9:00am
6
Sorry, think you missunderstand.
I need to modify the first code that controls the relay via serial, to work like a momentry switch as shown in the 2nd code.
Sorry if I wasnt clear.
nickrout
(Nick Rout)
April 30, 2024, 9:16am
8
switch:
- platform: template
name: "WIFI Relais EIN/AUS"
turn_on_action:
- uart.write: [0xA0, 0x01, 0x01, 0xA2]
turn_off_action:
- uart.write: [0xA0, 0x01, 0x00, 0xA1]
optimistic: true
id: relay
on_turn_on:
- delay: 800ms
- switch.turn_off: relay
A button could be an alternative to a switch here.
Optionally with the actions located under a script.
nickrout
(Nick Rout)
April 30, 2024, 9:50am
10
It’s documented. What I posted is documented. Just use the documentation.
1 Like
tom_l
April 30, 2024, 9:55am
11
A button would be a better fit in a dashboard.
switch:
- platform: template
id: relay # no name makes this internal only and not exposed to home assistant
turn_on_action:
- uart.write: [0xA0, 0x01, 0x01, 0xA2]
turn_off_action:
- uart.write: [0xA0, 0x01, 0x00, 0xA1]
optimistic: true
button:
- platform: template
name: "Gate Remote" # exposed to Home Assistant
on_press:
- switch.turn_on: relay
- delay: 800ms
- switch.turn_off: relay
2 Likes
nickrout
(Nick Rout)
April 30, 2024, 10:14am
12
You’re right. But the point is that the posted fix should work.
2 Likes
wcavanagh
(Will Cavanagh)
April 30, 2024, 12:44pm
13
Thanks all,
You are all amazing, it is working perfect.
wcavanagh
(Will Cavanagh)
April 30, 2024, 3:00pm
14
I have one more question guys.
How do I now trigger this button every 2 hours? Do I need to set an automation? Or is it done in the ESP code?
wcavanagh
(Will Cavanagh)
April 30, 2024, 3:38pm
15
Self fixing, found it in automations
1 Like