Turning on a plug at a certain humidity level

Good morning all,

I’ve been experiencing problems caused by humidity in the house. As a result I’ve bought a dehumidifier, which is working well. I’ve also bought a Zigbee Coordinator and added in a humidity sensor. This is now giving regular updates on the humidity and temperature in the room.

I have the dehumidifier plugged into a smart socket, I could just have it turn on at a certain time and off at another, but I’d rather it only came on when the humidity was over 55% and turned off when it was below 50% between the hours of 07:30 and 21:00.

The trend has been that it is over 70% by the morning, in winter, and I can get it below 50% in a couple of hours.

The difficulty that I am experiencing is that the script I’ve put together to run this automation is trying to use a numeric state, but it will not see the reading from the sensor as a number it gives the following error:

Error: In ‘numeric_state’ condition: entity sensor.bedroom_thermometer_humidity state ‘%’ cannot be processed as a number

I don’t know how to work around this. What other kind of trigger can I use to address this? Or is there a way to get this to recognise the readings from the sensor?

Any help would be much appreciated.

Tom

alias: Dehumidifier - On
sequence:
  - condition: numeric_state
    entity_id: sensor.bedroom_thermometer_humidity
    attribute: unit_of_measurement
    above: '55'
    below: '100'
  - condition: time
    after: '07:30'
    before: '21:00'
  - service: input_boolean.turn_on
    target:
      entity_id: input_boolean.humidity_high
mode: restart
icon: mdi:air-humidifier

That’s the yaml code from the UI for info.

Have you tried without attribute: unit_of_measurement ?

As pedolsky mentions remove the attribute.
What you are saying to the automation is to look at the attribute unit_of_measurement which I assume is % and compare that with a number.
If you remove that line it will look at the state which is a string but can be converted to number.

Edit is this a script you made?
I can’t see trigger only sequence.
You should have made it an automation.

1 Like

You can trigger it with a button in the UI.

Hi all,
Sorry, I’d gone out. I’ll try again with the suggestions above. I do have an automation that runs when the nominated input_boolean is activated, but it won’t activate.

I have tried it without the unit_of_measurement, but when I tried to run a trace on it there was nothing. So I’m just a bit confused as to what it is that I am doing wrong.

I’ll try the suggestions and come back here,

Thanks,

Tom

Tell us what you want.
Right now there are bits and pieces coming and the whole picture is not clear.

What is the input boolean for? Is this supposed to be an automation or script?

Apologies, I’ll try and start from scratch.

I’d originally tried to create an automation that used the same kind of format. If the times were between 07:30 and 21:00 and the humidity was over X amount turn on the plug. It didn’t work. I’d watched some videos saying about using scripts, so I tried it as a script that would trigger the input_boolean, which was probably unnecessary it was mostly so I could see if the script was working.

What I can’t get my head around is that the script won’t read the unit of measurement, because it wants a number, not a percentage, but when I don’t have the unit of measurement included it still doesn’t work. I’ve just set this going:

alias: Bedroom - Humidity - Dehumidifier OFF
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.bedroom_thermometer_humidity
    below: '54'
    above: '0'
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition: []
action:
  - type: turn_off
    device_id: 6e3ec59f5536ff29497b14aacfa334e1
    entity_id: switch.toothbrush_charger
    domain: switch
  - service: input_boolean.turn_off
    target:
      entity_id: input_boolean.humidity_high
mode: single

Alongside this:

alias: Bedroom - Humidity - Dehumidifier ON
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.bedroom_thermometer_humidity
    above: '55'
    below: '100'
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition:
  - condition: time
    after: '08:00'
    before: '21:00'
action:
  - service: switch.turn_on
    target:
      entity_id: switch.toothbrush_charger
  - service: input_boolean.turn_on
    target:
      entity_id: input_boolean.humidity_high
mode: single

So I’ll see if it works.

It’s switched the dehumidifier back on, which is a good start. Will have to see if it switches it off again and then see how it works in the morning.

Will it matter that it will be well above 55%?

Those automation seems to be correct.
Only that the input_boolean is not needed.

And that you could make it one automation using the id and choose.

Yes.

if it’s already above 55% when the condition is met then the automation action won’t run since the trigger (55%) has already come and gone.

you want to create both the trigger and the conditions as both triggers and conditions:

alias: Bedroom - Humidity - Dehumidifier ON
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.bedroom_thermometer_humidity
    above: '55'
    below: '100'
    for:
      hours: 0
      minutes: 5
      seconds: 0
  - platform: time
    at: '08:00'
condition:
  - condition: numeric_state
    entity_id: sensor.bedroom_thermometer_humidity
    above: '55'
  - condition: time
    after: '08:00'
    before: '21:00'
action:
  - service: switch.turn_on
    target:
      entity_id: switch.toothbrush_charger
  - service: input_boolean.turn_on
    target:
      entity_id: input_boolean.humidity_high
mode: single

Thanks,

What I’ve done is give the input Boolean purpose. It will come on overnight, but not turn on the plug. When a certain time is reached if the input Boolean is on then the plug will turn on.

I think that will work.