I have a dehumidifier that is hooked up to a wifi plug switch. I created a sensor that tracks whether it is running or not (sensor.dehumidifier) if it is using above a certain voltage it will be listed as running and below it is listed as idle. I created an automation to turn it on when the humidity is above 60%.
I also want it to turn off when it gets to 52% humidity. The one command works but the off command needed a condition because you shouldn’t stop it mid cycle. I have tried making the trigger off the humidity level with a condition that. I have also tried having it trigger if it is at the right humidity and then is idle but neither seem to trigger it. I have also tried adding a “from:” and making “Idle” lowercase. Any advice? YAML below.
- alias: Dehumidifier Off
trigger:
platform: state
entity_id: sensor.dehumidifier
to: "Idle"
condition:
- condition: numeric_state
entity_id: sensor.thermostat_humidity
below: 53
action:
service: switch.turn_off
entity_id: switch.dehumidifier
Does sensor.dehumidifer return “Idle” or “idle”? It sounds like you created it, so you’re in control of what it returns and case matters. Otherwise, it looks like it will do what you want - trigger whenever sensor.dehumidifier transitions to “Idle”, checks to see if sensor.thermostat_humidity is less than 53, and turns off the dehumidifier if it is.
When in doubt, check the states in Dev->States to see what values the entities have.
So if I understand correctly, the sensors.humidity sensor is telling you if the dehumidifier is actually using power and you don’t want to switch off until it’s both not using power and the humidity is low. I suspect your challenge is that the trigger fires whenever one condition becomes true. The other may not be true at that time. You need something to trigger when either value changes so that the condition can be reevaluated.
Why don’t you create a template sensor “dehumidifier_should_be_on” with both states in the value template. That will get evaluated whenever either changes. Then base your automations on that sensor value?
Thanks, Richard. I was afraid that might be the case. I didn’t think about making another sensor but I think you may be right about that. Everything has been working so well for so long I am going to have to dust off my template sensor making skill but that is probably for the best. I will try that when I can and get back to you there.
I assumed that the humidity drop while the humidifier was running would have been correlated, but I can see how they may not be and that would be a problem here. Another option is to trigger on the drop in humidity and use a wait_for_trigger to wait for the humidifier to stop before turning it off. Something like this:
- alias: Dehumidifier Off
trigger:
platform: numeric_state
entity_id: sensor.thermostat_humidity
below: 53
action:
- wait_for_trigger:
- platform: state
entity_id: sensor.dehumidifier
to: "Idle"
- service: switch.turn_off
entity_id: switch.dehumidifier
You could add a timeout there if you don’t want to wait forever.
Hmm, will that work if the dehumidifier sensor is already “idle” when the humidity drops? Say the unit finishes its cycle before the humidity crosses its threshold.
Really appreciate all the help @rccoleman and @RJA
I tried the template first but I couldn’t get it to pass a config check. I tried a few different formattings but ended up with this error.
“Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected char ‘‘’ at 81) for dictionary value @ data[‘sensors’][‘dehumidifier_safe_stop’][‘value_template’]. Got “{% if state_attr(‘switch.dehumidifier’, ‘current_power_w’)|float > 3.5 and state(‘sensor.thermostat_humidity’)|int > 53 %}\n Run\n{% else %}\n Stop\n{% endif %}”. (See ?, line ?).”
I am gonna test out Rob’s automation and see if it works as intended. I’ll update you when I no more. It should kick off tonight and I will have a better idea then.
The conditional automation is worth exploring I think. If that doesn’t work then the reason your template isn’t working is that the quote characters are wrong. Likely from me editing on an iPad. Just paste into HA and the replace each single and double quote with one you type - even if it looks right. We seem to have both forward and backward single quotes in there. That’s wrong. My code should also have said “states” for the second function - not “state”.
One advantage of the template sensor approach is that you’ll also end up with a new sensor in your logbook telling you appliance should have been on or off which could be useful.
Richard, you were correct after changing state to states and finding the ‘ instead of the ’ and replacing them the sensor was able to pass a check.
The automation did not fire last night as it was not running when it passed the threshold into 52 percent and then the A/C kicking on brought it down past the level it needed to be in to turn on automatically. Gonna watch it today and see if the following sensor and automation work.
dehumidifier_safe_stop:
friendly_name: "Dehumidifier Safe Stop"
value_template: >-
{% if state_attr('switch.dehumidifier', 'current_power_w')|float > 3.5 and states('sensor.thermostat_humidity')|int > 53 %}
Run
{% else %}
Stop
{% endif %}
- alias: Dehumidifier Off
trigger:
platform: state
entity_id: sensor.dehumidifier_safe_stop
to: "Stop"
action:
- service: switch.turn_off
entity_id: switch.dehumidifier
@rccoleman and @RJA
Thanks again for your time and consideration on this one! While the conditional automation still had some tweaking to do ultimately the template_sensor appears to be working as intended and will end up saving me some money in the process.
Well I thought I was out of the woods but it appears it only is going off the running state based of power usage and ignores the humidity portion. Not sure what to do about that. It will go into “stop” mode any time the device stops and ignores if the humidity is below 53%.