Troubleshooting an automation usint data template

I’m trying to have one light turn on and adjust it self to the same brightness as another light, when that light is turned on, or the brightness is changed. This isn’t working. I broken it out and gotten it to work with just a normal brightness service call in the third action, but as soon as I put in the data_template it doesn’t go beyond just turning on. What isn’t right about this? Thanks!

- action:
  - data:
      entity_id: light.cabinet_two
    service: light.turn_on
  - delay: 00:00:03
  - data_template:
      brightness: ‘{{ states.light.cabinet_one.attributes.brightness }}’
      entity_id: light.cabinet_two
    service: light.turn_on
  alias: light match brightness
  condition: []
  id: '1514560209130'
  trigger:
  - entity_id: light.cabinet_one
    platform: state

my log is giving me this error when I run the automation:

2017-12-29 15:51:37 ERROR (MainThread) [homeassistant.core] Invalid service data for light.turn_on: expected int for dictionary value @ data[‘brightness’]. Got ‘‘99’’

Perhaps try using ‘ or “ quotes on your template line (I deleted my previous suggestion of removing them)

Ok, I’m confused. Quotes where? I saw your original post that said to remove them. Do you mean to do it like this instead?

- action:
  - data:
      entity_id: light.cabinet_two
    service: light.turn_on
  - delay: 00:00:03
  - data_template:
      brightness: {{ 'states.light.cabinet_one.attributes.brightness' }}
      entity_id: light.cabinet_two
    service: light.turn_on
  alias: light match brightness
  condition: []
  id: '1514560209130'
  trigger:
  - entity_id: light.cabinet_one
    platform: state

The brightness attribute is being returned as a string, it needs to be converted to an integer to be passed to the brightness setting…

brightness: {{ states.light.cabinet_one.attributes.brightness | int  }}

No, sorry, I was just thinking you should use straight quotes and not curly ones. Also try converting to INT as already mentioned.

HA isn’t liking that… Getting this error upon restart:

2017-12-29 18:06:43 ERROR (MainThread) [homeassistant.bootstrap] Error loading /config/configuration.yaml: invalid key: “OrderedDict([(‘states.light.cabinet_one.attributes.brightness | int’, None)])”
in “/config/configuration.yaml”, line 158, column 0

I think it was the lack of quotes that was causing the errors and crashing HA. I added them back in and it booted, but the automation still doesn’t work. Still getting this error:

2017-12-29 18:40:32 ERROR (MainThread) [homeassistant.core] Invalid service data for light.turn_on: expected int for dictionary value @ data[‘brightness’]. Got ‘‘99’’

This is the line I have in there:

brightness: ‘{{ states.light.cabinet_one.attributes.brightness | int }}’

I dunno!!?!

Just to confirm, try this exact code and post any errors if not working…

- id: '1514560209130'
  alias: light match brightness
  trigger:
    platform: state
    entity_id: light.cabinet_one
  action:
    - service: light.turn_on
      entity_id: light.cabinet_two
    - delay: 00:00:03
    - service: light.turn_on
      data_template:
        brightness: {{ states.light.cabinet_one.attributes.brightness | int }}
        entity_id: light.cabinet_two

Ok, plugged it in, and it crashed HA. Here are the errors:

2017-12-29 19:32:53 ERROR (SyncWorker_0) [homeassistant.util.yaml] invalid key: “OrderedDict([(‘states.light.cabinet_one.attributes.brightness | int’, None)])”
in “/config/configuration.yaml”, line 163, column 0
2017-12-29 19:32:53 ERROR (MainThread) [homeassistant.bootstrap] Error loading /config/configuration.yaml: invalid key: “OrderedDict([(‘states.light.cabinet_one.attributes.brightness | int’, None)])”
in “/config/configuration.yaml”, line 163, column 0

Ugh, what on earth is an invalid key in this context :roll_eyes:

I take it it if you just stick a number in where the template is it works?

Like this? Not sure if data_template needs to be changed to just data

- id: '1514560209130'
  alias: light match brightness
  trigger:
    platform: state
    entity_id: light.cabinet_one
  action:
    - service: light.turn_on
      entity_id: light.cabinet_two
    - delay: 00:00:03
    - service: light.turn_on
      data_template:
        brightness: 100
        entity_id: light.cabinet_two

I think it should work like that, but try just data if not.

yes it works

As stated here:
3. You must surround single-line templates with double quotes (") or single quotes (').

So try this:

- id: '1514560209130'
  alias: light match brightness
  trigger:
    platform: state
    entity_id: light.cabinet_one
  action:
    - service: light.turn_on
      entity_id: light.cabinet_two
    - delay: 00:00:03
    - service: light.turn_on
      data_template:
        brightness: '{{ states.light.cabinet_one.attributes.brightness | int }}'
        entity_id: light.cabinet_two

Yes, have it that way now but still not working.

alright, so, thinking that maybe it was a problem with the switch it’s trying to pull the data, I’ve now tried a different switch, and a smart bulb, but neither worked and I’m still getting this error:

2017-12-29 20:47:17 ERROR (MainThread) [homeassistant.core] Invalid service data for light.turn_on: expected int for dictionary value @ data[‘brightness’]. Got ‘‘25’’

I don’t understand what the error is saying. It’s expecting ‘int’, which is an integer. It 'Got “25” '… which is an integer… soooooo, what’s the problem!!! I’m not sure what it means by ‘dictionary value’

Strange. What do you get if you put

{{ states.light.cabinet_one.attributes.brightness | int }}

in the template editor (in the Developer Tools menu) ?

If I put it in exactly as you have it, it gives me:

Error rendering template: UndefinedError: ‘mappingproxy object’ has no attribute ‘brightness’

If I put it in with out int, it goes blank.

Interesting. Is it the same when the light is on ? (or was it on already). Also, what kind of light is it?