I’m trying to make an automation when humidity (in bathroom) exceeds 75% a bed lamp will turn on. This is my idea to prepare bed light after shower.
I’ve been trying many solutions, but to no avail.
My sensor is: sensor.mi_h_bathroom (it’s from Xiaomi - LYWSD03MMC)
From what I’ve checked it is a string, so conversion needs to happen.
My light is: light.bed_lamp (IKEA tradfri GU10)
This works properly, returning true when it’s above 75. Tested on templates and I was setting state manually in states to emulate and try to get automation to work
{% if states.sensor.mi_h_bathroom.state | int > 75 %} true {% endif %}
I’ve tried with platform: numeric_state, but after reading forums it turned out when I checked, the sensor returns string, so this is probably why it didn’t work.
Here’s my automation.yaml with a few from my attempts:
Thanks for you input. I will check that soon. Am I right in thinking, that the automation should work even when I set the state manually through “States”?
Actually, I image this automation to be a bedtime, so I would like in the future to add time condition to it, which should be simple enough, and probably a counter so that it won’t be lighting the lamp up again after let’s say 1h, when I’m asleep and the humidity is still above 75.
Yeah, setting the state manually will work. The sensor will return to its correct state on its next update. Remember that for the automation to trigger the number must go from below 75 to above 75.
Thanks, tested and it works perfectly. Applying conditions now. Do you know if I can simulate time for the condition? For example set the current time to 15:00 for the purpose of test and how to set it back to the default one? Also, how can I check the time entity current value?
Thanks for your suggestion, but for now I don’t have smart lights in my bathroom and also toggling the lights doesn’t neccesarily mean I am taking a bath/shower, since my bedtime varies.
For future readers, I’m sharing my working automation.
The way it works: if humidity sensor in bahtroom exceeds 75% and it’s between 20:30 - 01:00 (shower time) and also the lamp has been off for at least 1 hour, turn on the lamp at 25% brightness
- alias: bed lamp on after shower
trigger:
platform: numeric_state
entity_id: sensor.mi_humidity_bathroom
above: 75
condition:
condition: and
conditions:
- condition: state
entity_id: light.bed_lamp_light
state: 'off'
for:
hours: 1
- condition: time
after: '20:30:00'
before: '01:00:00'
action:
service: light.turn_on
data:
entity_id: light.bed_lamp_light
brightness_pct: 25