Binary_sensor state automation not working

Hi.
I don’t get the reason why it doesn’t work.
Action separately works. What do I miss?

- id: Air Dryer Off
  alias: Air Dryer Off
  trigger:
    - platform: state
      entity_id: binary_sensor.power_usage_allowed
      to: 'off'
    - platform: numeric_state
      entity_id: sensor.room_humidity
      below: 50
  action:
    service: switch.turn_off
    entity_id: switch.smart_metering_switch_4

The action would fire when the state of that binary sensor changes to off OR when sensor.room_humidity goes below 50. If it’s already below 50, that trigger won’t cause the automation to fire. What do you mean it doesn’t work? (That is, what are you expecting to happen, and what is actually happening?)

If you are trying to get the switch to turn back off if it is turned on WHILE the humidity is below 50 you can put a time based trigger and associated conditions to accomplish this.

This will fire every minute and turn the switch off if the humidity is below 50 or the power_usage_allowed sensor is off.

- id: Air Dryer Off
  alias: Air Dryer Off
  trigger:
    - platform: state
      entity_id: binary_sensor.power_usage_allowed
      to: 'off'
    - platform: numeric_state
      entity_id: sensor.room_humidity
      below: 50
    # run every minute
    - platform: time_pattern
      minutes: '/1'
  condition:
    - condition: or
      conditions:
        - condition: state
          entity_id: binary_sensor.power_usage_allowed
          state: 'off'
        - condition: numeric_state
          entity_id: sensor.room_humidity
          below: 50
  action:
    service: switch.turn_off
    entity_id: switch.smart_metering_switch_4

Nor does anyone else. Please explain how you expect it to work and what it is actually doing.

My full on-off automation is the following:
I’m trying to turn on air dryer when humidity is above 53% and power usage binary sensor is on.
And turn it off when humidity falls to 50% or power usage is prohibited.
I did remake the automation with automation editor as well and the difference was that in action data section is used. Although I don’t understand why it is so.
It seems to work with new format now. But I haven’t yet tested all combinations.

- id: Air Dryer On
  alias: Air Dryer On
  trigger:
    platform: numeric_state
    entity_id: sensor.room_humidity
    above: 53
  condition:
    condition: state
    entity_id: binary_sensor.power_usage_allowed
    state: 'on'
    for:
      minutes: 2
  action:
  - data:
      entity_id: switch.smart_metering_switch_4
    service: switch.turn_on

- id: Air Dryer Off
  alias: Air Dryer Off
  trigger:
  - platform: state
    entity_id: binary_sensor.power_usage_allowed
    to: 'off'
  - platform: numeric_state
    entity_id: sensor.room_humidity
    below: 50
  action:
  - data:
      entity_id: switch.smart_metering_switch_4
    service: switch.turn_off

Looks good to me.

In my understanding it should of worked before as well. Without the “-data” section.

Yeah you don’t need data in that case. Service and entity ID is sufficient if you don’t have any other data. Not sure why it wouldn’t be working before, unless the automation wasn’t on.

it was on. After HA restarts humidity value could of been unknown for some time, but when it updated then it still didn’t actuate. I did manually flip the binary_sensor also. But it didn’t work either.
Side question: is there a way to receive humidity state as last state instead of unknown?