I have a d1-mini with a single momentary push button. I would like to set a variable to “x” on short press and to “y” on long press.
Then I want to decide what to do with those values in HA automation (that part I should be ok with)
This is what I have so far, perhaps it is a simple solution but I either cannot find it or I don’t understand the results from my searches…
binary_sensor:
- platform: gpio
pin:
number: D5
mode: INPUT_PULLUP
on_click:
- min_length: 50ms
max_length: 500ms
then:
# set some variable value = x
- min_length: 1000ms
max_length: 2000ms
then:
# set some variable value = y
filters:
- invert:
name: "Bedroom toggle"
I have found part of my problem, I am now able to execute the short on_click succesfully.
Stuck on the second part as soon as I add an “if” where I have my remarks, i get the red underlines indicating there is an error. Here is my updated code:
binary_sensor:
- platform: gpio
pin:
number: D5
mode: INPUT_PULLUP
on_click:
- min_length: 50ms
max_length: 500ms
then:
- homeassistant.service:
service: switch.toggle
data:
entity_id: switch.bedroom
- min_length: 1000ms
max_length: 2000ms
then:
# if a lamp is on then run HA automation 1
# else run HA automation 2
filters:
- invert:
name: "Bedroom toggle"
Sorry, I should have posted my complete code from the beginning.
Your last response pointed me to the need to create an id, looking at examples I added the lamp_status within the sensor section under platform homeassistant but I get an error indicating lamp_status is not a switch. Tried to add it to the switch section but getting an error indicating switch.homeassistant does not exist…
Thank you @Karosm and @zenzay42 for your help.
I have a lot less hair on my head now but I finely got it working.
The only thing I could get working in the condition is lambadas
and I was not able to execute automations but it worked with scripts so I created scripts to launch the automations.
What this code does is from a d1-mini (esp8236) with a single push button; A quick push will toggle the lamps on my bed side and a long push will either turn on or off all lights in the house. The only issue with this is it will not help with weight loss.