Compare Inside to Outside Temperature and close windows when outside too hot

Hi,

I need a special automation rule which needs more then simple actions…

I have a WUnderground Weather Station (outside) and also Fibaro Motion Sensor (inside)

My goal ist to get the following working:

If the outside temperature is higher then the inside temperature and also the outside temperature is higher then 23 Degree Celsisus I want to close the roof windows.

The Automation I think I can do it myself, but for comparing the temperature values I guess I will need a value_template? Here I am struggeling how I could to the comparision…

Br,
Johannes

Take a look at this example I fould searching the forums.

  trigger:
    platform: time
    minutes: '/1'
    seconds: 01
  condition:
    platform: template
    value_template: "{{ ( states.sensor.inside_temp.state  ) < ( states.sensor.outside_temp.state ) }}"
  action:
   service: switch.turn_on
   entity_id: switch.window

Found the thread here

1 Like

Still fighting with the multiple conditions…

I want to check the template_value as well as the input_boolean. But somehow this config is wrong.

Br,
Johannes

- alias: 'Arbeitszimmer Dachfenster automatisch schließen '
  trigger:
  - platform: time
    minutes: '/5'
    seconds: 00
  condition:
  - condition: template
    value_template: "{{ ( sensor.arbeitszimmer_dach_motion_sensor_temperature  ) < ( states.sensor.pws_temp_c ) }}"
  - condition: state
    entity_id: input_boolean.temperaturvergleich
    state: 'on'
  action:
  - data:
      message: Arbeitszimmer Dachfenster werden wegen Außentemperatur geschlossen
      title: Arbeitszimmer Dachfenster werden geschlossen
    service: notify.pushover_johannes
      entity_id: input_boolean.temperaturvergleich
    service: input_boolean.turn_off

How about something like this:

- alias: 'Arbeitszimmer Dachfenster automatisch schließen '
  trigger:
    platform: template
    value_template: >
      {{ states.sensor.pws_temp_c.state > 
           states.sensor.arbeitszimmer_dach_motion_sensor_temperature.state }}
  condition:
    - condition: numeric_state
      entity_id: sensor.pws_temp_c
      above: 23
    - condition: state
      entity_id: input_boolean.temperaturvergleich
      state: 'on'
  action:
    - service: notify.pushover_johannes
      data:
        message: Arbeitszimmer Dachfenster werden wegen Außentemperatur geschlossen
        title: Arbeitszimmer Dachfenster werden geschlossen
    - service: input_boolean.turn_off
      entity_id: input_boolean.temperaturvergleich

EDIT: To expand a bit… :slight_smile:

There are a few issues with your automation. First, you’re triggering it every 5 minutes. That’s not necessary. It can “wake up” (automatically) anytime the inside or outside temperature changes to check how they compare. (This is what I’m doing in the template trigger.)

Next, in a template you (generally) need to use states.entity_id.state or states('entity_id').

Lastly, in your action section you have two actions, but only one ‘-’. Each action (e.g., each service) needs its own ‘-’.

Let me know if you have any questions. Happy to explain further.

1 Like

Many thanks,

The trigger “every 5 minutes” was for “if someone opens the window manually, it should close again”.

REgarding the action: This is the problem, when creating automations via the Fronted, then they look different to what users do manually and then it is hard to understand. I think I should completley go away from editing via the frontend.

So many thanks again for your help!

Br,
Johanne

Again, you shouldn’t need to check every 5 minutes, unless that’s what you want to do. I.e., if you want the window to close if someone opens it under certain conditions, then that’s the way you should write the automation. The main thing to remember is the trigger part is the “when” part, and the condition part is the “if” part. :slight_smile:

Well, the frontend editor shouldn’t let you create an invalid automation. But, yes, it does tend to format unnaturally. I gave it a shot when I first started with HA, but within about 37 milliseconds I decided to skip it and edit the files directly.

In any case, glad you got it working! :smile:

1 Like

Hi,

It is still not working, I guess becasue the compare option. Need to troubleshoot further.

But first I need to understand the rule:

   value_template: >
      {{ states.sensor.pws_temp_c.state > 
           states.sensor.arbeitszimmer_dach_motion_sensor_temperature.state }}

Is the first > a special operator or only due to break up the rule into multiple lines?

Br,
Johannes

Multiple lines. https://yaml-multiline.info/

1 Like

How so? Is it causing errors? Or is it just not doing what you want. If the former, what is the error? If the latter, maybe you could explain what you’re wanting it to do that it isn’t. (I may have misunderstood your requirements.)

My mistake, it seems it is working. i am now monitoring with notifications.

Br.
Johannes

Good to hear! BTW, it’s helpful if you check one of the “Select if this reply solves the problem” check boxes so others scanning through the list of topics looking to provide help know that your problem is solved and you don’t need help with it anymore. :slight_smile:

Thanks for the hint. Will do it.

1 Like

Hi, another question to this compare function: Can I adopt it like:

if 1st value is greater then the "second value minus X"

Br,
Johannes

Yes. It would then just be something like:

    value_template: >
      {{ states.sensor.pws_temp_c.state > 
           states.sensor.arbeitszimmer_dach_motion_sensor_temperature.state - 10 }}

This works if these states are actually numbers. If they are numbers represented by a string (which sometimes happens, and is also sometimes hard to tell), then you could do this instead:

    value_template: >
      {{ states.sensor.pws_temp_c.state|int > 
           states.sensor.arbeitszimmer_dach_motion_sensor_temperature.state|int - 10 }}

The |int part is called a filter. This particular one converts a number string to an integer number.

Hi,

but with int it would ignore decimal values like 21.5?

Br,
Johannes

True. Then replace |int with |float.