Fan automation based on temperature

it could be but I don’t think it will do what you expect it to do…

Look at your triggers in the “on” automation. The way you have it set up now (ignoring the conditions for now) the actions will be performed in the following circumstances:

  1. every time the sensor.netatmo_cucina_temperature state changes. it will fire every time the temp goes up or down by only 1 degree

  2. every time the device_tracker.iphone_matteo goes into the home zone

  3. every day at 9 am

  4. on the first day of spring

  5. on the first day of summer

some of those triggers seem strange to me, especially the last two. But even some of the others look strange given your conditions.

Also I do see one syntax error but that might just be a copy/paste error.

If those triggers really are what you want to happen then I would rewrite the conditions like below to fix the possible syntax errors:

condition:
  - condition: time
    after: '09:00:00'
    before: '21:00:00'
  - condition: numeric_state
    entity_id: sensor.netatmo_cucina_temperature
    above: 21
  - condition: zone
    entity_id: device_tracker.iphone_matteo
    zone: zone.home

automation should work only in spring and summer, only when matteo is at home, when the temperature exceeds 24 degrees. it should only work between 9:00 am and 9:00 pm and depending on the temperature the various ventilation levels should be automatically selected for speed.

I understand what you are TRYING to do. But what you have isn’t that. you have the automation TRIGGERING on those things not conditionally running based on those things.

read the automation again looking at your triggers vs conditions.

should I cancel the various triggers leaving only the presence of Matteo at home and everything else goes in the conditions?

It might be easier to tell you for sure if you write out exactly how you expect it to work. list what event(s) should happen when you want it to turn on and which exact conditions need to be met.

Then we can work thru how to set it up correctly.

activation is that matteo must be at home.
the condition is that the season is spring or summer and that the temperature must be higher than 24 degrees centigrade, and the activation time must be between 9 and 21 hours.

- id: 'Ventilatore_fan_on'
  alias: Ventilatore_Fan On
  trigger:
    - platform: zone
      entity_id: device_tracker.iphone_matteo
      zone: zone.home
      event: enter
  condition:
    - condition: time
      after: '09:00:00'
      before: '21:00:00'
    - condition: numeric_state
      entity_id: sensor.netatmo_cucina_temperature
      above: 24
    - condition: or
      conditions:
        - condition: state
          entity_id: sensor.season
          state: spring
        - condition: state
          entity_id: sensor.season
          state: summer
  action:
    - service: fan.set_speed
      entity_id: fan.smartmi_fan
      data_template:
        speed: >
          {% set temp = states('sensor.netatmo_cucina_temperature')|float %}
          {% if temp > 24 %} Level 1
          {% elif temp > 26 %} Level 2
          {% elif temp > 28 %} Level 3
          {% else %} Level 4
          {% endif %}
    - service: notify.ios_iphone_matteo
      data:
        title: "Smart Home Alerts"
        message: 'Ventilatore ON - temperatura {{ states("sensor.netatmo_cucina_temperature") }} C'
    - data:
        effect: 'WhatsApp'
        entity_id: light.cucina_3
      service: light.turn_on

This automation will trigger the actions only when matteo enters the home zone but only if the conditions as you specified above exist at that moment in time.

I haven’t tested it since I don’t have your entities so I would get errors. So make sure you do a config check and then report if you get any errors.

does automation still work if matteo is at home during the day and the temperature increases during the day?
that is, if at 9 o’clock the temperature is 20 degrees and at 11 o’clock the temperature reaches 25 degrees, does the automation still activate? thank you

No.

You didn’t specify that in your last post above. you only said you wanted it to activate if you got home during those specified conditions.

That’s why I asked you to list all of the things in the way to wanted it to come on and the conditions required.

This should do it. I think…:

- id: 'Ventilatore_fan_on'
  alias: Ventilatore_Fan On
  trigger:
    - platform: zone
      entity_id: device_tracker.iphone_matteo
      zone: zone.home
      event: enter
    - platform: numeric_state
      entity_id: sensor.netatmo_cucina_temperature
      above: 24
  condition:
    - condition: state
      entity_id: device_tracker.iphone_matteo
      state: 'home'
    - condition: time
      after: '09:00:00'
      before: '21:00:00'
    - condition: numeric_state
      entity_id: sensor.netatmo_cucina_temperature
      above: 24
    - condition: or
      conditions:
        - condition: state
          entity_id: sensor.season
          state: spring
        - condition: state
          entity_id: sensor.season
          state: summer
  action:
    - service: fan.set_speed
      entity_id: fan.smartmi_fan
      data_template:
        speed: >
          {% set temp = states('sensor.netatmo_cucina_temperature')|float %}
          {% if temp > 24 %} Level 1
          {% elif temp > 26 %} Level 2
          {% elif temp > 28 %} Level 3
          {% else %} Level 4
          {% endif %}
    - service: notify.ios_iphone_matteo
      data:
        title: "Smart Home Alerts"
        message: 'Ventilatore ON - temperatura {{ states("sensor.netatmo_cucina_temperature") }} C'
    - data:
        effect: 'WhatsApp'
        entity_id: light.cucina_3
      service: light.turn_on

of course it should always work when matteo is at home even if he doesn’t go out for a day. that is, always when matteo is at home

For when I’m home, as well as the trigger @finity suggested, I have this automation to change the speed.

  - id: lounge_fan_speed_change
    alias: Lounge Fan Speed Change
    trigger:
      - platform: numeric_state
        entity_id: sensor.wirelesstag_lounge_temperature
        below: 28
      - platform: numeric_state
        entity_id: sensor.wirelesstag_lounge_temperature
        above: 28
      - platform: numeric_state
        entity_id: sensor.wirelesstag_lounge_temperature
        below: 30
      - platform: numeric_state
        entity_id: sensor.wirelesstag_lounge_temperature
        above: 30
    condition:
      condition: and
      conditions:
        - condition: numeric_state
          entity_id: sensor.wirelesstag_lounge_temperature
          above: 26
        - condition: state
          entity_id: fan.lounge_fan
          state: 'on'
        - condition: state
          entity_id: binary_sensor.people_home
          state: 'on'
    action:
      - service: fan.set_speed
        entity_id: fan.lounge_fan
        data_template:
          speed: >
            {% set temp = states('sensor.wirelesstag_lounge_temperature')|float %}
            {% if temp < 28 %} low
            {% elif temp < 30 %} medium
            {% else %} high
            {% endif %}

I’m sure there’s a way to make it neater and have only one automation. But, this works.

I have another question to propose:
how do i do this kind of action using date_template?

- id: 'Ventilatore fan on'
  alias: Ventilatore Fan On
  trigger:
    - platform: zone
      entity_id: device_tracker.iphone_matteo
      zone: zone.home
      event: enter
    - platform: state
      entity_id: sensor.netatmo_cucina_temperature
  condition:
    - condition: time
      after: '09:00:00'
      before: '22:00:00'
    - condition: numeric_state
      entity_id: sensor.netatmo_cucina_temperature
      above: 23
    - condition: or
      conditions:
        - condition: state
          entity_id: sensor.season
          state: spring
        - condition: state
          entity_id: sensor.season
          state: summer
    - service: fan.xiaomi_miio_set_natural_mode_
      entity_id: fan.smartmi_fan
      data_template:
        speed: >
          {% set temp = states('sensor.netatmo_cucina_temperature')|float %}
          {% if temp < 24 %} on
          {% elif temp < 25 %} on
          {% elif temp < 26 %} off
          {% else %} off
          {% endif %}

fan.xiaomi_miio_set_natural_mode_ can be on or off

the template looks OK. It doesn’t make any sense but it is technically OK.

The issue you will run into is it’s going to start at the first if statement to see if it’s true. If the temp is less than 24 the result is on. If not it jumps to the next if. If that’s true then the result is on. Why not just say <25 in the first if and get rid of the second one.

then also if the temp is between 25 and 26 there is no difference between that and >26 so no reason for that step either…

you forgot the action: statement. and you also need to put the entity_id under data:

- id: 'Ventilatore fan on'
  alias: Ventilatore Fan On
  trigger:
    - platform: zone
      entity_id: device_tracker.iphone_matteo
      zone: zone.home
      event: enter
    - platform: state
      entity_id: sensor.netatmo_cucina_temperature
  condition:
    - condition: time
      after: '09:00:00'
      before: '22:00:00'
    - condition: numeric_state
      entity_id: sensor.netatmo_cucina_temperature
      above: 23
    - condition: or
      conditions:
        - condition: state
          entity_id: sensor.season
          state: spring
        - condition: state
          entity_id: sensor.season
          state: summer
  action:  
    - service: fan.xiaomi_miio_set_natural_mode_
      data_template:
        speed: >
          {% set temp = states('sensor.netatmo_cucina_temperature')|float %}
          {% if temp < 25 %} on
          {% else %} off
          {% endif %}
        entity_id: fan.smartmi_fan

could this service work?
Service fan.xiaomi_miio_set_natural_mode_on
Service fan.xiaomi_miio_set_natural_mode_off

  • service: fan.xiaomi_miio_set_natural_mode_
    entity_id: fan.smartmi_fan
    data_template:
    speed: >
    {% set temp = states(‘sensor.netatmo_cucina_temperature’)|float %}
    {% if temp < 24 %} on
    {% elif temp < 25 %} on
    {% elif temp < 26 %} off
    {% else %} off
    {% endif %}

or i need another kind of syntax

this is complete automation

- id: 'Ventilatore fan on'
  alias: Ventilatore Fan On
  trigger:
    - platform: zone
      entity_id: device_tracker.iphone_matteo
      zone: zone.home
      event: enter
    - platform: state
      entity_id: sensor.netatmo_cucina_temperature
  condition:
    - condition: time
      after: '09:00:00'
      before: '22:00:00'
    - condition: numeric_state
      entity_id: sensor.netatmo_cucina_temperature
      above: 23
    - condition: or
      conditions:
        - condition: state
          entity_id: sensor.season
          state: spring
        - condition: state
          entity_id: sensor.season
          state: summer
  action:
    - service: fan.set_speed
      entity_id: fan.smartmi_fan
      data_template:
        speed: >
          {% set temp = states('sensor.netatmo_cucina_temperature')|float %}
          {% if temp < 24 %} 25
          {% elif temp < 25 %} 50
          {% elif temp < 26 %} 75
          {% else %} 100
          {% endif %}
    - service: fan.xiaomi_miio_set_natural_mode_
      entity_id: fan.smartmi_fan
      data_template:
        speed: >
          {% set temp = states('sensor.netatmo_cucina_temperature')|float %}
          {% if temp < 24 %} on
          {% elif temp < 25 %} on
          {% elif temp < 26 %} off
          {% else %} off
          {% endif %}

i think that speed is not correct

https://github.com/syssi/xiaomi_fan

I have a question about the design of you automation’s trigger.

As written, it triggers whenever the temperature rises or falls at two thresholds: 28 and 30.

In other words, when temperature rises above 28 to 29, it triggers, and when it rises above 30, it triggers again. Similarly, when it falls below 30 to 29, it triggers, and when it falls below 28 it triggers yet again.

What’s the purpose of having two thresholds?

I have literally no idea what you’re trying to do.

I assumed you knew the correct service to use. Apparently you don’t.

I can’t tell you what speeds are correct. It’s your equipment. I would think you should know that.

and you completely ignored my advice on the template without explaining why I’m wrong.

I apologize for not understanding what you love you were suggesting …
what I would like to do is if the temperature is below 26 degrees the fan.xiaomi_miio_set_natural_mode_on service should be activated.
if it is higher, fan.xiaomi_miio_set_natural_mode_off.
the speed part works fine.
I wanted to add the fan.xiaomi_miio_set_natural_mode_on service by comparing it with the temperature sensor.

is correct?

- id: 'Ventilatore fan on'
  alias: Ventilatore Fan On
  trigger:
    - platform: zone
      entity_id: device_tracker.iphone_matteo
      zone: zone.home
      event: enter
    - platform: state
      entity_id: sensor.netatmo_cucina_temperature
  condition:
    - condition: time
      after: '09:00:00'
      before: '22:00:00'
    - condition: numeric_state
      entity_id: sensor.netatmo_cucina_temperature
      above: 23
    - condition: or
      conditions:
        - condition: state
          entity_id: sensor.season
          state: spring
        - condition: state
          entity_id: sensor.season
          state: summer
  action:
    - service: fan.set_speed
      entity_id: fan.smartmi_fan
      data_template:
        speed: >
          {% set temp = states('sensor.netatmo_cucina_temperature')|float %}
          {% if temp < 24 %} 25
          {% elif temp < 25 %} 50
          {% elif temp < 26 %} 75
          {% else %} 100
          {% endif %}
    - entity_id: fan.smartmi_fan
      service_template: >
          {% set temp = states('sensor.netatmo_cucina_temperature')|float %}
          {% if temp < 25 %} 
            fan.xiaomi_miio_set_natural_mode_off
          {% else %} 
            fan.xiaomi_miio_set_natural_mode_off
          {% endif %}

it’s closer…

try this:

- id: 'Ventilatore fan on'
  alias: Ventilatore Fan On
  trigger:
    - platform: zone
      entity_id: device_tracker.iphone_matteo
      zone: zone.home
      event: enter
    - platform: state
      entity_id: sensor.netatmo_cucina_temperature
  condition:
    - condition: time
      after: '09:00:00'
      before: '22:00:00'
    - condition: numeric_state
      entity_id: sensor.netatmo_cucina_temperature
      above: 23
    - condition: or
      conditions:
        - condition: state
          entity_id: sensor.season
          state: spring
        - condition: state
          entity_id: sensor.season
          state: summer
  action:
    - service: fan.set_speed
      entity_id: fan.smartmi_fan
      data_template:
        speed: >
          {% set temp = states('sensor.netatmo_cucina_temperature')|float %}
          {% if temp < 24 %} 25
          {% elif temp < 25 %} 50
          {% elif temp < 26 %} 75
          {% else %} 100
          {% endif %}
    - entity_id: fan.smartmi_fan
      service_template: >
          {% set temp = states('sensor.netatmo_cucina_temperature')|float %}
          {% if temp < 26 %} 
            fan.xiaomi_miio_set_natural_mode_on
          {% else %} 
            fan.xiaomi_miio_set_natural_mode_off
          {% endif %}
1 Like

@123 The trigger changes the fan speed.