Triggers and Conditions

Hi, please apologies if asked already but I’m trying to understand the Triggers and Conditions and when I trigger manually a automation if they are respected…

Scenario: I have an automation that will check if any of the Temps across the house are bellow 18 and if so, turns on the boiler(heating) but I do not want this to happen if none of us is home.

This is what I have:

- id: '1547051043616'
  alias: Turn Heating ON IF Cold
  trigger:
  - below: '18'
    entity_id: sensor.netatmo_the_inside_temperature
    for: 00:15:00
    platform: numeric_state
  - below: '18'
    entity_id: sensor.netatmo_the_otherside_temperature
    for: 0:15:00
    platform: numeric_state
  - below: '18'
    entity_id: sensor.kitchen_temp
    platform: numeric_state
  condition:
  - condition: state
    entity_id: input_select.house_occupancy
    state: 'Home'
  action:
  - entity_id: switch.arest_pin_one_boiler
    service: homeassistant.turn_on
  - data:
      message: Turning the Heating ON for 60mins...its cold...
      title: Heating ON
    service: notify.ios_joaos_iphone
  - delay: 01:00:00
  - entity_id: switch.arest_pin_one_boiler
    service: homeassistant.turn_off
  - data:
      message: Turning the Heating OFF after 60mins...it was cold...
      title: Heating OFF
    service: notify.ios_joaos_iphone

For the check if we’re at home I’m using something I found on this forum to setup a extra input:

input_select:
  house_occupancy:
    name: Where are we?
    options:
     - Away
     - Home
     - Holidays
    icon: mdi:home-map-marker

And the automation for this is:

- id: '1547464779330'
  alias: Presence - no one home
  hide_entity: true
  trigger:
    platform: state
    entity_id: group.phoneslocations
    to: not_home
    for:
      minutes: 15
  action:
    service: input_select.select_option
    data:
      entity_id: input_select.house_occupancy
      option: Away
- id: '1547464770330'
  alias: Presence - someone home
  hide_entity: true
  trigger:
    platform: state
    entity_id: group.phoneslocations
    to: home
    for:
      minutes: 5
  action:
    service: input_select.select_option
    data:
      entity_id: input_select.house_occupancy
      option: Home

Now, if I trigger this manually it always turns on no mater if the input_select.house_occupancy is set to Home or Away. But if I let it just run it won’t trigger at all.
Now I know that without the Conditions it will trigger since it happened this night. Unless, do my triggers need to all be under 18 for it to be actioned or its “or”.

So the questions:

1 - Is it expected that if I run manually it will turn the boiler on? Even with the status set to Away.
2 - Should I define condition to Away or Home?
3 - What I’m I doing wrong? :smile:

Thanks for the help in advance.

You have it all figured out, but you just missed a spot:

You answers:
1- Yes. As far as I know, when you manually trigger an automation, it just goes off no matter what the conditions are.
2- Away. Think of it like that:

When do I trigger? When temp is below 18 for 15’
IF everyone is away

3- The condition :slight_smile:

Something I noticed is that you are missing the for: 00:15:00 on the kitchen_temp trigger. Did you forget it? :stuck_out_tongue:

EDIT:

I should read more carefully… You want it to trigger when you are HOME… so your condition is correct.
Try without quotes and see if it triggers

  condition:
  - condition: state
    entity_id: input_select.house_occupancy
    state: Home

Thanks for the reply @argykaraz.
Yes you are correct, I was missing the for: 00:15:00

I’ve also removed the Quotes from home.

On that note, unless I missunderstood I do want to do the reverse of what you said…

When do I trigger? When temp is below 18 for 15’
IF everyone is Home

I changed the code and manually updated the input_select to be Home and still no joy :cry:

See the temp. It has been bellow 18 for quite some time, so it should have triggered, so I’m wondering if it needs to be on the same temp, not heigher or lower than 18 for 15 mins? I mean if goes to 17.5 then 17.3 in the space of less than 15 mins it will not trigger? :confused:

Home_Assistant

Thanks once again.

try leaving your original automations like they were except remove the quotes from around the numbers in the trigger.

trigger:
  - below: 18
    entity_id: sensor.netatmo_the_inside_temperature
    for: 00:15:00
    platform: numeric_state
  - below: 18
    entity_id: sensor.netatmo_the_otherside_temperature
    for: 0:15:00
    platform: numeric_state
  - below: 18
    entity_id: sensor.kitchen_temp
    platform: numeric_state

Thanks for the reply @finity.
I was just testing that. I was just also wondering if it requires a number and the values that the temp sensor is adding are floats?

To add to this:

{% if states.sensor.netatmo_the_otherside_temperature.state|float < 18 %} true {% endif %}
{% if states.sensor.netatmo_the_inside_temperature.state|float < 17 %} true {% endif %}
{% if states.sensor.kitchen_temp.state|float < 18 %} true {% endif %}

This returns true… but if I remove the |float I get no results… :confused:

As the name implies it does require a number (not a string) which is why you need to remove the ’ because that denotes a string.

It doesn’t matter if the number is an int or a float. You can use both.

ah… well it makes sense… I’ll give it a go… this is what I have now:

- id: '1547051043616'
  alias: Turn Heating ON IF Cold
  initial_state: true
  trigger:
  - platform: numeric_state
    entity_id: sensor.netatmo_the_otherside_temperature
    below: 17
    for: 0:15:00
  - platform: numeric_state
    entity_id: sensor.netatmo_the_inside_temperature
    below: 17
    for: 0:15:00
  - platform: numeric_state
    entity_id: sensor.kitchen_temp
    below: 17
    for: 00:15:00
  condition:
  - condition: state
    entity_id: input_select.house_occupancy
    state: Home
  action:
  - service: homeassistant.turn_on
    entity_id: switch.arest_pin_one_boiler
  - service: notify.ios_joaos_iphone
    data:
      message: Turning the Heating ON for 60mins...its cold...
      title: Heating ON
  - delay: 01:00:00
  - service: homeassistant.turn_off
    entity_id: switch.arest_pin_one_boiler
  - service: notify.ios_joaos_iphone
    data:
      message: Turning the Heating OFF after 60mins...it was cold...
      title: Heating OFF

And I’ve manually forced: input_select.house_occupancy to Home

So if I’m reading correctly it should take around 5 mins to trigger since looking at the temps:

Home_Assistant

The Living room is bellow the trigger value…

Interesting… eventually it did turn on but the automation fired 4 times…

Home_Assistant

Any ideas? Thanks

the only thing I can think is that the temp sensor is “hovering” around the setpoint and every time it goes above and then back below the setpoint it triggers again.

What does the history show for your temp sensor?

1 Like

The hovering can not do it as there is the FOR condition. One thing I can think of would be that temperatures were below trigger limit, you would have 4 temp triggers and reloaded the automations. This way all of them would trigger after set 15 min. But as you have only 3 this can’t be the case…

I would also prevent the automation running again when the boiler has been turned on the first time. So add a condition that the boiler needs to be off. This way if one of the temperatures would cause another trigger the automation is not interfered.

I’m not sure if your one hour delay in the automation is 100% safe. I would make another automation to turn the boiler off after it has been on for one hour. And maybe link it to some input_boolean if you are controlling the boiler from some other places also.

1 Like

Thanks for all the replies.
So two things… the duplication of the Automations, seems to be a bug on the latest HA version. So I’ve rolled back for now. GitHub issue here: #19970

Yes, you are correct, running with a delay is not a good idea, and I’ve also added a status check to see if the boiler is already on. So this is what I have at the moment.

- id: '1547051043616'
  alias: Turn Heating ON IF Cold
  trigger:
  - below: 17
    entity_id: sensor.netatmo_the_inside_temperature
    for: 00:15:00
    platform: numeric_state
  - below: 17
    entity_id: sensor.netatmo_the_otherside_temperature
    for: 0:15:00
    platform: numeric_state
  - below: 17
    entity_id: sensor.kitchen_temp
    for: 00:15:00
    platform: numeric_state
  condition:
  - condition: state
    entity_id: input_select.house_occupancy
    state: Home
  - condition: state
    entity_id: sensor.boiler_status
    state: '0'
  action:
  - entity_id: switch.timed_boiler
    service: homeassistant.turn_on
  - data:
      message: Turning the Heating ON for 60mins...its cold...
      title: Heating ON
    service: notify.ios_joaos_iphone

The good news is that it triggered twice during the night… The bad news is that I’m not sure if it triggered correctly. Looking at the temps it seems it was Ok to be triggered but then again… So I’ll keep monitoring…

I think this is not correct:

    entity_id: sensor.boiler_status
    state: '0'

Now it means a sting “0” and not a number zero. You can always check the entity value used by home assistant in the entity menu <> on the left panel.

Yes I think you are right @taikapanu.
But HA was trowing an error when using without the quotes. So I’ve replaced with:

 - condition: state
    entity_id: switch.timed_boiler
    state: 'off'

This should make it better now :slight_smile: Thanks