Serching topics

is there any trick for searching posts using the words trigger and AND where
AND is the logical AND ?

I’m trying to find how to trigger on two events , where both must have happened, but not getting anywhere

Looking at the first example, I think AND is assumed in automation triggers

# Example of entry in configuration.yaml
automation:
# Turns on lights 1 hour before sunset if people are home
# and if people get home between 16:00-23:00
  - alias: 'Rule 1 Light on in the evening'
    trigger:
      # Prefix the first line of each trigger configuration
      # with a '-' to enter multiple
      - platform: sun
        event: sunset
        offset: '-01:00:00'
      - platform: state
        entity_id: group.all_devices
        to: 'home'
    condition:
      # Prefix the first line of each condition configuration
      # with a '-'' to enter multiple
      - condition: state
        entity_id: group.all_devices
        state: 'home'
      - condition: time
        after: '16:00:00'
        before: '23:00:00'
    action:
      # With a single service call, we don't need a '-' before service - though you can if you want to
      service: homeassistant.turn_on
      entity_id: group.living_room

Thanks
I’ve a lot similar to that in my automations.yaml
trying to trigger with A.B but it only wants to play with A+B
I guess the only way is to trigger on time every 5 ~10 minutes and test for A.B

try templates mate https://www.home-assistant.io/components/template/

check this out : Help with if-statement

Multiple triggers are handled as logical OR.

From the first paragraph of the documentation for Automation Trigger:

It is possible to specify multiple triggers for the same rule - when any of the triggers becomes true then the automation will start.

In contrast, multiple conditions can be handled as either AND or OR. If neither is specified, it defaults to AND.

The documentation contradicts itself then. See the quote from my official page.

Triggers monitor changes such as when a switch changes from off to on, a temperature sensor increases from 21 to 22, time increments to a new value, etc.

Conditions are filters that check current state.

The combination of the two allows you to trigger when a door opens then check if the current time is later than a given threshold.

Determining what should be the trigger and what should be the condition depends on the intended application.

What is the application you have in mind?

Hiya
What I trying to do is turn power off somewhere when both of us are out , both mobile phones on device_traker.
What I’ve ended up doing is to check every 10 minutes if both phones are on the wifi network.
Its not as quick .
while yer there , is it possible to change the state of a boolean input device from within an automation ?

I’m having trouble spotting the contradiction. Is it the comment in the automation?

Make the automation trigger on either device_tracker then, in its condition, it checks if both device_trackers are ‘not_home’.

When the first person leaves, nothing happens because the condition detects only one of the two device_trackers is ‘not_home’. The other one is still ‘home’.

When the second person leaves, the condition is satisfied because now both device_trackers are ‘not_home’ and the action is executed to turn off the lights.

Yes, there are services available for that:
input_boolean.turn_on
input_boolean.turn_off
input_boolean.toggle

To see the available services, go to Home Assistant’s Services page and scroll through the Service list.

thanks I’ll have another go in the morning

In its simplest form the automation would look something like this one. It triggers if either of the two device_trackers become ‘not_home’ and executes the action only if both trackers are ‘not_home’.

- alias 'Nobody home'
  trigger:
    platform: state
    entity_id: device_tracker.phone1, device_tracker.phone2
    to: 'not_home'
  condition:
    condition: template
    value_template: "{{ is_state('device_tracker.phone1', 'not_home') and is_state('device_tracker.phone2', 'not_home') }}"
  action:
    service: homeassistant.turn_off
    entity_id: group.all_lights

If you foresee the need to create other automations that trigger based on who is, or is not, home then you’re better off creating a template sensor that reports occupancy. This one monitors the two device_trackers and then reports occupancy as one of four states:

  • nobody
  • richard
  • sue
  • everybody
- platform: template
  sensors:
    occupants:
      entity_id: device_tracker.phone1, device_tracker.phone2
      value_template: >-
        {% set modes = ['nobody', 'richard', 'sue', 'everybody'] %}
        {% set p1 = 1 if is_state('device_tracker.phone1', 'home') else 0 %}
        {% set p2 = 2 if is_state('device_tracker.phone2', 'home') else 0 %}
        {{ modes[p1 + p2] }}

Now it becomes easier to create automations that trigger on occupancy:

- alias 'Nobody home'
  trigger:
    platform: state
    entity_id: sensor.occupants
    to: 'nobody'
  action:
    service: homeassistant.turn_off
    entity_id: group.all_lights

You can also do trickier things like trigger if you are the last person to leave the house.

- alias 'Richard leaves home last'
  trigger:
    platform: state
    entity_id: sensor.occupants
    from: 'richard'
    to: 'nobody'
  action:
    service: homeassistant.turn_off
    entity_id: group.all_lights

Or detect if you are the first person to arrive.

- alias 'Richard arrives home first'
  trigger:
    platform: state
    entity_id: sensor.occupants
    from: 'nobody'
    to: 'richard'
  action:
    service: homeassistant.turn_on
    entity_id: group.all_lights

isn’t this the same as the person component?

Thanks , I’d got close to that but the condition template makes that much easier

I moved on a bit futher, I found that triggering on the device tracker was taking a long time, only on the phones, so I used time pattern

This is giving me a problem , it works until is ANDed with the state between times

  - alias: shack power if Richard is home
    trigger:
      platform: time_pattern
      minutes: '/2'
    condition:
      condition: and
      conditions:
        - condition: template
          value_template: "{{ is_state('device_tracker.android_7ad792e3b1647c4f_lan','home')}}"    
        - condition: template
          value_template: "{{ is_states.sensor.time.state > '08:30' and states.sensor.time.state < '22:00' }}"
    action:
      service: homeassistant.turn_on 
      entity_id: switch.shack_power 

the config checker is happy with syntax, but I suspect I’ve written rubbish, where did I screw up. ?
The wanted respose is, if my phone is seen at home and its between 0830 and 2200 turn the shack power on

Can you re-state this? I have no idea what you are saying there.

It work s until the line where the the condition on time is logically AND with the other conditions

Why don’t you just use a state and time condtion? The template only complicates things imho as these are very straight forward conditions.

And you should actually add another condition to only trigger when the state of switch.shack_power is off.

remove the "is_’ from in front of the second value template first compare.

  - condition: template
    value_template: "{{ states.sensor.time.state > '08:30' and states.sensor.time.state < '22:00' }}"