Hello there, I am new to Home Assistant and so far really enjoying it.
I am at a bit of a block though, I have HA installed on a Raspberry PI 3 B + as a headless install (OS), so far, I have installed Tuya integration for 3 bulbs and 2 plugs, I have a DHT22 sensor reading humidity and temp (hard wired to the PI), I also have a Plex integration that is really fun for some automations.
That being said, I would like to install a physical momentary button (GPIO 2 to GND) on the PI so that I can automate activating HA created scenes on the bulbs, EG: one click = brightness 100% on all bulbs. Two clicks = bubls off. (or switch.toggle would be nice too).
I have read numerous threads that say use the binary_sensor option, but it just won’t work for me and I do not have any idea how to start troubleshooting, I did also create manual YAML automations, which work when I press the "Run Automation’ in HA.
What I added to the configuration.yaml for the button looks like so;
binary_sensor:
- platform: rpi_gpio
ports:
3: Bedroom Lights
What I added to the automation.yaml looks like so; (this was from one of the mentioned threads I read)
- alias: Light Mode Short # toggle main lights on and off "Bright"
trigger:
- platform: state
entity_id: binary_sensor.bedroom_lights
from: 'on'
to: 'off'
condition:
condition: template
value_template: "{{ (as_timestamp(now())-as_timestamp(states.binary_sensor.bedroom_lights.last_changed)) < 1 }}"
action:
- scene: scene.bright
mode: single
Any help is appreciated! PS: I hope I am not in the wrong section…
Hello, I got the button working with the one automation (Had to invert the logic in my config.YAML), Is there a way for me to have the scene.bright
toggle instead of just turning on with a single click? (I tried using the switch.toggle
service but that did not work.
- alias: Light Mode Short # main lights on "Bright"
trigger:
- platform: state
entity_id: binary_sensor.bedroom_lights
from: 'on'
to: 'off'
condition:
condition: template
value_template: "{{ (as_timestamp(now())-as_timestamp(states.binary_sensor.bedroom_lights.last_changed)) < 1 }}"
action:
- scene: scene.bright
mode: single
My next issue is that the press and hold for 3 seconds automation is not working, and I have no clue where to start.
- alias: Light Mode Long # scene Ambient "Dim"
trigger:
platform: state
entity_id: binary_sensor.bedroom_lights
from: 'on'
to: 'off'
condition:
condition: template
value_template: "{{ (as_timestamp(now())-as_timestamp(states.binary_sensor.bedroom_lights.last_changed)) > 3 }}"
action:
- scene: scene.dim
mode: single
I tried the from: to: for: 3 seconds
but that caused any button press to activate scene.dim
Okay, so I pretty much made a round about way for a toggle option that I wanted…
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- alias: Light Mode Short # toggle main lights on and off "Bright"
trigger:
- platform: state
entity_id: binary_sensor.bedroom_lights
from: 'on'
to: 'off'
condition:
condition: template
value_template: "{{ (as_timestamp(now())-as_timestamp(states.binary_sensor.bedroom_lights.last_changed)) < 1 }}"
action:
- scene: scene.bright
mode: single
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- alias: Light Mode Short # toggle main lights on and off "Bright"
trigger:
- platform: state
entity_id: binary_sensor.bedroom_lights
from: 'on'
to: 'off'
condition:
- condition: state
entity_id: light.light
state: "on"
- condition: state
entity_id: light.light_wall
state: "on"
- condition: state
entity_id: light.light_ceiling
state: "on"
action:
- scene: scene.bedroom_off
mode: single
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Its ugly, but it works and I can live with it. I will just go ahead and mark this as solved
Thanks!