Automating lights using MQTT and plex

so, I’ve definitely done some searching before asking and, I haven’t found anything that fixes things, yet.
anyway.
I’m sure I’m no the first to want to do this, and I won’t be the last.
on trying to run this (config check, actually) I get an incredibly vague error with [line?, column ?] so, that’s helpful… something about expecting dictionary value for condition. I can recreate if needed.
though, iv’e definitely narrowed it down, through trial and error, and commenting out things…
on to the nasty stuff that is my config…

  - alias: Change living room lights with Plex
    initial_state: True
    hide_entity: False
    trigger:
      platform: mqtt
      topic: "tautulli/status"
    condition: and
    conditions:
      - condition: or
        conditions:
          - condition: template
            value_template: "{{ 'play' in trigger.payload}}"
          - condition: template
            value_template: "{{ 'resume' in trigger.payload}}"
      -  condition: template
         value_template: "{{ 'movie' in trigger.paylod}}"
    action:
      service: light.turn_off
      data:
        entity_id: light.philips_lwb014_03197653_11

I made sensors for this as well but, those appear to be working as intended, though I can post those if needed as well. I didn’t figure having the bulb names would be detrimental but, I can strike that if someone thinks I’m putting national security in jeopardy.

if it helps, here are the sensors as well

# play status of plex, via tautulli
  - platform: mqtt
    name: PlexPlayStatus
    state_topic: tautulli/status
    value_template: '{{value_json.body}}'

#type of movie, via tautulli
  - platform: mqtt
    name: PlexMediaType
    state_topic: tautulli/status
    value_template: '{{value_json.subject}}'

hopefully I’m just dumb and missed something obvious.

EDIT: fixed indentation on “initial_state”

The only thing less vague is no error message at all, which is what everyone else can see.

But your indentation looks incorrect - initial_state is one space over.

indentation was not in config. likely from me removing comment.

here’s the error it sends when I use the check config button.

Invalid config for [automation]: expected a dictionary @ data['condition'][0]. Got None
extra keys not allowed @ data['conditions']. Got None. (See ?, line ?).

This means the first condition should have some entries beneath it

This mean that conditions is not allowed at the same level as the previous.

So I think you need to indent the first condtions: by a couple of spaces.

ok so, I’ve added, what I thought, would be appropriate indentations, given that that one needed.

  - alias: Change living room lights with Plex
    initial_state: True
    hide_entity: False
    trigger:
      platform: mqtt
      topic: "tautulli/status"
    condition: and
      conditions:
        - condition: or
            conditions:
              - condition: template
                value_template: "{{ 'play' in trigger.payload}}"
              - condition: template
                value_template: "{{ 'resume' in trigger.payload}}"
        -  condition: template
           value_template: "{{ 'movie' in trigger.paylod}}"
    action:
      service: light.turn_off
      data:
        entity_id: light.philips_lwb014_03197653_11

now I get “mapping values not allowed here”

if I use the yaml checker HA suggests, it’s at line 109, which in that first “conditions”
if I use the config checker, it’s at line 116, which is that last “- condition: template”

EDIT: I apologize for not knowing more

I don’t think anyone needs to apologize for not knowing something. But it would be helpful if you pasted the actual error message, rather than your summary.

here’s the error given by HA’s own config checker

Error loading /home/homeassistant/.homeassistant/configuration.yaml: mapping values are not allowed here
  in "/home/homeassistant/.homeassistant/configuration.yaml", line 116, column 17

and here’s the one from YAMLLint

(unknown): mapping values are not allowed in this context at line 109 column 17

That really doesn’t make sense to me. However, I am looking at the Mixed And And Or Condtions example, which seems to match your use, and it has an extra condtion: at the start. So I suggest you use that as a template.

If it doesn’t work, I’ll give up with yaml automations and go back to appdaemon again.

so, this passes YAMLLint

  - alias: Change living room lights with Plex
    initial_state: True
    hide_entity: False
    trigger:
      platform: mqtt
      topic: "tautulli/status"
      condition:
      condition: and
      conditions:
        - condition: or
          conditions:
            - condition: template
              value_template: "{{ 'play' in trigger.payload}}"
            - condition: template
              value_template: "{{ 'resume' in trigger.payload}}"
        -  condition: template
           value_template: "{{ 'movie' in trigger.paylod}}"
    action:
      service: light.turn_off
      data:
        entity_id: light.philips_lwb014_03197653_11

but, I still get

Invalid config for [automation]: [condition] is an invalid option for [automation]. Check: automation->trigger->0->condition. (See ?, line ?).

from the config checker

EDIT: Fixed error message

sorry to double post

I changed the indentation to match the link you sent

  - alias: Change living room lights with Plex
    initial_state: True
    hide_entity: False
    trigger:
      platform: mqtt
      topic: "tautulli/status"
      condition:
        condition: and
        conditions:
          - condition: or
            conditions:
              - condition: template
                value_template: "{{ 'play' in trigger.payload}}"
              - condition: template
                value_template: "{{ 'resume' in trigger.payload}}"
          -  condition: template
             value_template: "{{ 'movie' in trigger.paylod}}"
    action:
      service: light.turn_off
      data:
        entity_id: light.philips_lwb014_03197653_11

same error from HA

That seems to match the example. I am going back to appdaemon - I know how to write Python.

Hopefully, someone smarter than me can help you.

thanks anyway!

alright so, I’ll throw this here for anyone who might want it in the future…
I abandoned the template thing and just used states, since I had already made sensors.
(maybe that was obvious? I’m new…)

here’s my automation, that functions as intended. (when pressing Play, or Resuming from pause, with Movies)

  - alias: Lights off with Plex (Play, Resume)
    initial_state: True
    hide_entity: False
    trigger:
      platform: mqtt
      topic: "tautulli/status"
    condition:
      condition: and
      conditions:
        - condition: or
          conditions:
            - condition: state
              entity_id: sensor.plexplaystatus
              state: 'play'
            - condition: state
              entity_id: sensor.plexplaystatus
              state: 'resume'
        - condition: state
          entity_id: sensor.plexmediatype
          state: 'movie'
    action:
      service: light.turn_off
      data:
        entity_id: light.philips_lwb014_03197653_11

EDIT: more info here!

just for those curious in the future:
I’ve setup a notification agent within Tautulli to send MQTT messages on Play, Pause, Resume, and Stop, when the stream is local and from MY user.

1 Like