New to both Home Assistant and coding here, apologies if I am not well-versed in the proper language. I’ve looked at some other posts here but couldn’t quite find the solution.
I’ve been trying to make an automation to trigger a smart plug to turn on when humidity falls below 50%. However, the automation does not currently trigger by itself. If I test the automation manually, the Smart Plug does turn on. Current humidity is below 50, and the plug is off. i have confirmed that the entity ID is correct. Seems it may be the writing of my trigger that is the issue, perhaps?
I am looking to use the humidity sensor inside my Dyson air purifier. I understand that the Dyson integration is not an official integration by HA so I know it’s possible I am having errors with the HACS integration. However, I’d like to rule out the coding options first if possible before making any assumptions about the integration as this is not listed as a known issue. I am able to see the humidity% on my dashboard so I know the sensor data is there.
I was hoping to create other parameters for this (only run between 11:30PM and 9:30AM, turn off when humidity is above 50, etc.) but for the moment have it simplified it for ease of debugging and just getting the initial trigger fixed.
No, just your understanding of how it triggers. The humidity must cross from above 50 to below 50 to trigger the automation. If it is already below 50 when you write or reload the automation it wont trigger until it goes above then falls below 50.
The best way around this is to add some more triggers and a condition:
alias: Humidity Control
description: ""
trigger:
- platform: numeric_state
entity_id:
- sensor.bedroom_dyson_humidity
below: 50
- platform: homeassistant
event: start
- platform: event
event_type: automation_reloaded
condition:
- condition: numeric_state
entity_id: sensor.bedroom_dyson_humidity
below: 50
action:
- service: switch.turn_on
metadata: {}
data: {}
target:
device_id: 0a1faa0c97de9aab893663ac090fdd2a # use an entity id here not a device id.
mode: single
The other way to do this is to trigger on all changes of your humidity sensor and check the level in the conditions:
alias: Humidity Control
description: ""
trigger:
- platform: state
entity_id:
- sensor.bedroom_dyson_humidity
not_to:
- unknown
- unavailable
condition:
- condition: numeric_state
entity_id: sensor.bedroom_dyson_humidity
below: 50
action:
- service: switch.turn_on
metadata: {}
data: {}
target:
device_id: 0a1faa0c97de9aab893663ac090fdd2a # use an entity id here not a device id.
mode: single
The disadvantage here is that the automation triggers a lot more often than it needs to.
You have not created an automation to turn off the switch either.
One final thing:
This only tests the actions. It skips triggers and conditions. If you use the Developer Tools → Services tool to run the automation trigger service you can include the conditions if you wish to.
Ahh yes, that makes sense. Thank you for clarifying this.
Indeed, I was just looking to understand how to create the trigger before adding that in.
I was aware this only tests the actions, which helped rule out any problem with the switch and narrowed it down to triggering. I didn’t know about the Developer tools method though, thank you for explaining.
Appreciate the thorough reply! I will make these changes.