Automation of Fan in Bathroom

Hi. i am new to HA, previously using TUYA app and devices. I am trying to move over to HA and tried my first Automation. but it will just not work.

I have placed a Zigbee Adaptor in my HA system and added a Temp/Humidty Sensor in the bathroom
I can see the data from the sensor.

I have a double switch for the bathroom, a Smart TUYA controlled switch. one for the light, one for the Fan.
I have tried the follwoing automation, to trigger the Fan switch to turn on, when the Humidty gets above 70 %. but it fails to do so

Any idea on why? its probably my basic errors on first try on automations,

id: '1789576973776'
alias: 'Bathroom fan on '
description: ''
triggers:
  - trigger: humidity.crossed_threshold
    target:
      entity_id: sensor.sonoff_snzb_02m_humidity
    options:
      behavior: all
      for: '00:00:00'
      threshold:
        type: above
        value:
          active_choice: number
          number: 70.1
          entity: sensor.sonoff_snzb_02m_humidity
conditions: []
actions:
  - action: switch.turn_on
    metadata: {}
    target:
      entity_id: switch.bathroom_light_switch_2
    data: {}
mode: single

I don’t see any glaring issues.

The most common source of confusion for Numeric State and the purpose-specific crossed_threshold triggers is that the value actually has to cross the threshold for the trigger to fire. If the humidity is already above the threshold when you create the automation, the trigger needs to be “reset” by the value going below the threshold. It will the fire when next it goes above the threshold.

For testing purposes, you can fake this process using the “Set State” function of the State tool. Change the value of the state to a number below your threshold, then wait for the state to receive an update from the device and se if the automation triggers.

Alternatively, you could use a humidity.changed trigger with a threshold. Just note that this type of trigger will fire more often than the humidity.crossed_threshold trigger, so you may need to add extra conditions for more specific control over the execution of the Actions.

Humidity Changed Automation Example
triggers:
  - trigger: humidity.changed
    target:
      entity_id: sensor.sonoff_snzb_02m_humidity
    options:
      threshold:
        type: above
        value:
          active_choice: number
          number: 70
          unit_of_measurement: null
conditions:
  - condition: switch.is_off   
    target:
      entity_id: switch.bathroom_light_switch_2
    options:
      for: '00:01:00'
actions:
  - action: switch.turn_on
    metadata: {}
    target:
      entity_id: switch.bathroom_light_switch_2
    data: {}
mode: single

Yes, but is there a sensor that detects obnoxious odor?

This is what I did:

alias: 'Bathroom: Bathroom Fan Auto-On'
description: Turn on Bathroom Vent When Humidity is High
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.bathroom_humidity
    above: 80
conditions:
  - condition: fan.is_off
    target:
      entity_id: fan.bathroom_vent
    options: {}
actions:
  - action: fan.turn_on
    metadata: {}
    target:
      entity_id: fan.bathroom_vent
    data: {}
  - wait_for_trigger:
      - trigger: numeric_state
        entity_id:
          - sensor.bathroom_humidity
        below: 65
  - action: fan.turn_off
    metadata: {}
    target:
      entity_id: fan.bathroom_vent
    data: {}
mode: single

Check the update interval on the temp sensor.
Some manufactures allow you to adjust it.
By default, it may be very high (> 10 minutes).

Note: If it’s a battery device sending updates may have a detrimental effect on battery life - for planning purposes doubling the update frequency may halve the battery life.

I use an outdoor sensor and I dropped it’s update frequency to 5 minutes which is a reasonable compromise for my use case.

I have a sensor that updates often up to once per second I think (bluetooth), and use a derivation helper.
When the humidity increases more than 2 I boost the ventilation.