As far as the usefulness of constants, here’s one place I’d normally use a constant, and I’m curious what you guys would recommend for HA YAML.
So I have motion sensors in our bathrooms to turn on/off the lights. Cool. But when you get into the shower and close the door/curtain, the sensor no longer detects motion and turns the lights off. Now you’re showering in the dark. Not cool.
My current solution to this problem is to put a humidity sensor near the shower. Then add a condition to the “Lights Off” automation that it only activates if the humidity is below a certain value. No more unhappy wife. But… I’m still experimenting with exactly what value to use as the humidity trigger.
Especially considering I have multiple bathrooms that use this humidity value, instead of coding a literal value (i.e. magic number), I’d normally define a constant for this… but I don’t see a way to do that in HA YAML.
Example:
- id: 'spam'
alias: Motion Lights Off - Master Bath
trigger:
- entity_id: binary_sensor.master_bath_motion_sensor_motion
for: 00:02:00
platform: state
to: 'off'
condition:
- below: '65'
condition: numeric_state
entity_id: sensor.master_bath_humidity_sensor_humidity
action:
- data:
transition: 5
entity_id: light.master_bath_lights
service: light.turn_off
In the above example, I’d love to be able to define a constant for the “65” and maybe even for the “5” on the transition to make tweaking things easier when those values are used in multiple automations. Suggestions?