Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 111588

How to trigger automation based off two states simultaneously?

$
0
0

Hi! I am doing my first bigger automation for a ‘goodnight’ routine.

I want to run my speaker to play some rain sounds overnight when a) both phones are in the bedroom, b) both phones are charging, and c) it’s past 10:30pm.

I more or less got this working, but right now it seems the order in which the phones are placed is crucial for the automation to begin. I don’t want the automation to start until both phones are charging, but I also want it to start no matter which phone is placed on to charge first.

Can someone please let me know if I’m just doing it wrong, or if there is a better way of doing it? Or do I just need to double up and add both phones to the trigger and both phones to the wait-for-trigger?

P.S. Bonus points for anyone who knows why the looping of the media also doesn’t seem to work? Is there a way to loop the one hour audio file?

alias: Play rain sounds overnight
description: ''

# One phone placed charging
trigger:
  - platform: state
    entity_id: sensor.iphone_ONE_battery_state
    to: Charging

# Two phones must be in the bedroom (using room-assistant)
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: sensor.ONE_iphone_room_presence
        state: bedroom-ra
      - condition: state
        entity_id: sensor.TWO_iphone_room_presence
        state: bedroom-ra

# Must be between 10:30pm and before 6am
  - condition: time
    after: '22:30:00'
    before: '06:00:00'

# Don't start automation until second phone begins to charge
action:
  - wait_for_trigger:
      - platform: state
        entity_id: sensor.iphone_TWO_battery_state
        from: Not Charging
        to: Charging
    continue_on_timeout: false

# Lower volume of speaker
  - service: media_player.volume_set
    target:
      device_id: 57d870a7d52cdc5a780091aeb1ed158f
    data:
      volume_level: 0.25

# Say goodnight
  - service: tts.google_cloud_say
    data:
      entity_id: media_player.bedroom_speaker
      message: Good night!
      cache: true

# Small delay to give enough time to wake speaker up and say goodnight
  - delay:
      hours: 0
      minutes: 0
      seconds: 6
      milliseconds: 0

# Begin playing Google's rain sounds locally
  - service: media_player.play_media
    data:
      media_content_id: https://mydomain.com/local/audio/rain.mp3
      media_content_type: music
    target:
      device_id: 57d870a7d52cdc5a780091aeb1ed158f

# Set media to repeating so rain sounds continue to loop the entire night (one hour audio file)
  - service: media_player.repeat_set
    target:
      device_id: 57d870a7d52cdc5a780091aeb1ed158f
    data:
      repeat: all
mode: single

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 111588

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>