Need help with two automations

I’ve got two automations using the service_template. The first one should set Hue bulbs to 100% brightness when turned on. The second one is turning on two Hue bulbs and two switches controlled by Smartthings. Neither of them is working correctly. The first one fails completely when birghtness_pct included. The second, only the Smartthings switches turn on or off, the Hue bulbs aren’t working at all.

Any suggestions? I’m including my current code. First is called Master Bedroom Switch and the second is Living Room Switch.

  alias: Master Bedroom Switch
  initial_state: false
  trigger:
  - entity_id: switch.master_bedroom_switch
    platform: state
    to: 'on'
  - entity_id: switch.master_bedroom_switch
    platform: state
    to: 'off'
  trigger:
    platform: mqtt
    topic: "smartthings/Master Bedroom Switch/switch"
  action:
    entity_id: light.master_bedroom
    service_template: >
      {% if trigger.payload == 'on' %}
        light.turn_on
		brightness_pct: 100
      {%- else -%}
        light.turn_off 

  alias: Living Room Switch
  initial_state: false
  trigger:
  - entity_id: switch.living_room_switch
    platform: state
    to: 'on'
  - entity_id: switch.living_room_switch
    platform: state
    to: 'off'
  trigger:
    platform: mqtt
    topic: "smartthings/Living Room Switch/switch"
  action:
    entity_id: light.living_room
    service_template: >
      {% if trigger.payload == 'on' %}
        light.turn_on
      {%- else -%}
        light.turn_off
      {% endif %}
    entity_id: switch.living_room_outlets
    service_template: >
      {% if trigger.payload == 'on' %}
        script.living_room_outlets_on
      {%- else -%}
        script.living_room_outlets_off
      {% endif %}

You can only include one trigger block in each automation. Also you can simplify your first automation trigger:

  alias: Master Bedroom Switch
  initial_state: false
  trigger:
    - platform: state
      entity_id: switch.master_bedroom_switch # will trigger with any change of state
    - platform: mqtt
      topic: "smartthings/Master Bedroom Switch/switch"
  action:
    entity_id: light.master_bedroom
    service_template: >
      {% if trigger.payload == 'on' %}
        light.turn_on
		brightness_pct: 100
      {%- else -%}
        light.turn_off 

There’s duplicate trigger blocks in your second automation too.

There’s probably more but I have to go.

2 Likes

you can’t have more than one line of code inside the ‘if/else’ statements.

Maybe the easiest would be to use the if/else logic to call different scripts which can contain all the actions you want depending on the different conditions.

there may be another way to do it but off the top of my head I’d try it that way.

Also there’s no {% endif %} statement in the first automation.