Automation with IF statement

Hello forum - i really need your help (im noob)

I have a sensor called sensor.tautulli_last_msg where i get tautulli / plexpy massages. (user action player)
example: admin play Chrome
so what i want to do is (something like this):

IF the sensor.tautulli_last_msg = admin play Chrome
“brightness_pct”: 10,
“color_name”: “red”,
“entity_id”: “light.altan”

OR IF the sensor.tautulli_last_msg = admin pause Chrome
“entity_id”: “light.altan”,
“brightness_pct”: 50,
“color_name”: “white”

OR IF the sensor.tautulli_last_msg = admin stop Chrome
“entity_id”: “light.altan”

The last step is OFF

Any wise men or woman out there, that can help?

There are some “fancier” ways to do this, but the simplest and most straightforward is to create an automation for each of these. The first might look like this:

trigger:
  platform: state
  entity_id: sensor.tautulli_last_msg
  to: admin play Chrome
action:
  service: light.turn_on
  entity_id: light.altan
  data:
    brightness_pct: 10
    color_name: red

Yeah i already tried that out and it did work BUT i had a problem with my off sequens,
i wantet to: (off action)
{
“entity_id”: “light.altan”,
“brightness_pct”: 50,
“color_name”: “white”
delay: 00:01:00
then light.off
}

and this was an issue because when i watch a tv show on my tv (plex) after an episode is finish i go back to plex and thats starts this sequens ,so that means i can start a new / next episode and it will turn red but after 1 minute the light will turn off

That’s a little hard to follow, but I think you’re looking for something like this:

trigger:
  platform: state
  entity_id: sensor.tautulli_last_msg
  to: admin stop Chrome
action:
- service: light.turn_on
  entity_id: light.altan
  data:
    brightness_pct: 50
    color_name: white
- delay: '00:01:00'
- service: light.turn_off
  entity_id: light.altan

hmm let me explain…

i have these automations:

START AND RESUME

alias: 1_Altan_start_resume
trigger:

  • platform: mqtt
    topic: tautulli
  • entity_id: sensor.tautulli_last_msg
    platform: state
    to: playback_start
    condition:
  • condition: state
    entity_id: sensor.tautulli_last_msg
    state: Local has startet streaming
    action:
  • data:
    brightness_pct: 10
    color_name: red
    entity_id: light.altan
    service: light.turn_on¨

PAUSE

alias: 1_Altan_pause
trigger:

  • platform: mqtt
    topic: tautulli
  • entity_id: sensor.tautulli_last_msg
    platform: state
    to: playback_paused
    condition:
  • condition: state
    entity_id: sensor.tautulli_last_msg
    state: Local has paused streaming
    action:
  • data:
    brightness_pct: 50
    color_name: white
    entity_id: light.altan
    service: light.turn_on

STOP

alias: 1_Altan_stop
trigger:

  • platform: mqtt
    topic: tautulli
  • entity_id: sensor.tautulli_last_msg
    platform: state
    to: playback_stop
    condition:
  • condition: state
    entity_id: sensor.tautulli_last_msg
    state: Local has stopped streaming
    action:
  • data:
    brightness_pct: 50
    color_name: white
    entity_id: light.altan
    service: light.turn_on
  • delay: 00:01:00
  • data:
    entity_id: light.altan

and the problem is , lets say i watch an episode and decide to stop (NOT PAUSE) and continue again
then the lights will turn red (like it suppose to) but after 1 minute it will turn off (because my #STOP setup)

I hope this is more explained…

Please format the YAML code properly.

hmm let me explain…

i have these automations:

#START AND RESUME
alias: 1_Altan_start_resume
trigger:

platform: mqtt
topic: tautulli
entity_id: sensor.tautulli_last_msg
platform: state
to: playback_start
condition:
condition: state
entity_id: sensor.tautulli_last_msg
state: Local has startet streaming
action:
data:
brightness_pct: 10
color_name: red
entity_id: light.altan
service: light.turn_on¨

#PAUSE
alias: 1_Altan_pause
trigger:

platform: mqtt
topic: tautulli
entity_id: sensor.tautulli_last_msg
platform: state
to: playback_paused
condition:
condition: state
entity_id: sensor.tautulli_last_msg
state: Local has paused streaming
action:
data:
brightness_pct: 50
color_name: white
entity_id: light.altan
service: light.turn_on

#STOP
alias: 1_Altan_stop
trigger:

platform: mqtt
topic: tautulli
entity_id: sensor.tautulli_last_msg
platform: state
to: playback_stop
condition:
condition: state
entity_id: sensor.tautulli_last_msg
state: Local has stopped streaming
action:
data:
brightness_pct: 50
color_name: white
entity_id: light.altan
service: light.turn_on
delay: 00:01:00
data:
entity_id: light.altan

and the problem is , lets say i watch an episode and decide to stop (NOT PAUSE) and continue again
then the lights will turn red (like it suppose to) but after 1 minute it will turn off (because my #STOP setup)

I hope this is more explained…

Phil means that you use the </> button above (in the text editing box header) and paste your code into the slot it creates, you can also insert the back ticks manually if you prefer.
It’s very hard to read code and assess yaml compliance if the thing you are looking for is invisible.

hmm let me explain…

i have these automations:

- id: '1567447711685'
  alias: 1_Altan_start_resume
  trigger:
  - platform: mqtt
    topic: tautulli
  - entity_id: sensor.tautulli_last_msg
    platform: state
    to: playback_start
  condition:
  - condition: state
    entity_id: sensor.tautulli_last_msg
    state: Local has startet streaming
  action:
  - data:
      brightness_pct: 10
      color_name: red
      entity_id: light.altan
    service: light.turn_on
- id: '1567447961743'
  alias: 1_Altan_pause
  trigger:
  - platform: mqtt
    topic: tautulli
  - entity_id: sensor.tautulli_last_msg
    platform: state
    to: playback_paused
  condition:
  - condition: state
    entity_id: sensor.tautulli_last_msg
    state: Local has paused streaming
  action:
  - data:
      brightness_pct: 50
      color_name: white
      entity_id: light.altan
    service: light.turn_on
- id: '1567445672196'
  alias: 1_Altan_stop
  trigger:
  - platform: mqtt
    topic: tautulli
  - entity_id: sensor.tautulli_last_msg
    platform: state
    to: playback_stop
  condition:
  - condition: state
    entity_id: sensor.tautulli_last_msg
    state: Local has stopped streaming
  action:
  - data:
      brightness_pct: 50
      color_name: white
      entity_id: light.altan
    service: light.turn_on
  - delay: 00:01:00
  - data:
      entity_id: light.altan
    service: light.turn_off


and the problem is , lets say i watch an episode and decide to stop (NOT PAUSE) and continue again
then the lights will turn red (like it suppose to) but after 1 minute it will turn off (because my #STOP setup)

I hope this is more explained…

Well done, that will help the people trying to help you
Cheers

Here you go :slight_smile:

First, your triggers and conditions are strange. Why do you have a trigger for sensor.tautulli_last_msg changing to 'playback_stop', but then have a condition that it must be 'Local has stopped streaming'? And you have an mqtt trigger. What is that for?

It would seem to me that what you should have is just the following trigger, and no condition, as I suggested earlier (even though you’ve changed the details since then):

trigger:
  platform: state
  entity_id: sensor.tautulli_last_msg
  state: 'Local has stopped streaming'

But regarding your original question, I think I finally understanding what you’re trying to say. I.e., if you stop, and then play again within one minute of stopping, the stop automation will still be running and will eventually turn the light off. If so, then probably the easiest way to solve that problem is don’t do that! :wink: But if you must, then the next easiest thing is to add a condition step after the delay but before the turn off to check to see if the last message is still stop:

  action:
  - data:
      brightness_pct: 50
      color_name: white
      entity_id: light.altan
    service: light.turn_on
  - delay: 00:01:00
  - condition: state
    entity_id: sensor.tautulli_last_msg
    state: Local has stopped streaming
  - data:
      entity_id: light.altan
    service: light.turn_off

But if you insist on pushing buttons too fast, even this won’t work. E.g., if you stop, then start, then stop again before the one minute delay has finished from the first stop, then the stop automation will abort the delay step and immediately turn the light off. That, unfortunately, is how automations work. So you’d need to move the actions into a script, then stop and start the script from the automation action. That’s the usual way to deal with that issue.

1 Like

Thanks mate!!!
That was just what i was looking for :slight_smile: