Turning off a switch with template errors, can't find the issue

      - service: switch.turn_off
        entity_id: >
          switch.vijverpomp_{{'links' if now().day % 2 else 'rechts'}}

is accepted by the config checker, but it throws an error in the log and notification:

while the template is fine:

what obvious mistake am I making here?
Please help me out with a keen eye

      - service: switch.turn_off
        data:
          entity_id: >
            switch.vijverpomp_{{'links' if now().day % 2 else 'rechts'}}

Just because we can now use data: instead of data_template: does not mean you can leave it out altogether when using templates.

1 Like

thanks! been staring at that for some time now, as you can see in the occurrences count… cant believe I missed that.
thanks again Tom, appreciated.

still, the mysterious ways of the config checker. Firstly, the above incorrect syntax was accepted, and just now, I made a typo:

      - service: switch.turn_off
        data:
          entity_id: >
            switch.vijverpomp_links {{'links' if now().day % 2 else 'rechts'}}

and that was accepted also!

      - service: switch.turn_off
        data:
          entity_id: >
            switch.vijverpomp_{{'links' if now().day % 2 else 'rechts'}}

it is from now on :wink:

forget this post, I made a typo… didnt delete for reference

config checker only validates what’s configured for the field. Your validation worked because it fits the validation sequence. It was most likely validated against switch.vijverpomp_linksifnowday2elserechts. Basically all special characters removed. Validator can’t find everything :wink: . for future referece, you should try to migrate to always using target or keeping your entity_id inside data. Entity_id outside won’t be deprecated but it’s the only area where templates aren’t applied.

A yes, I understand now.
It was a bit of a puzzle trying too find the correct automation… in the ‘old’ days, reloaded per edit in the file, to be sure which edit, or at least file cases an error. Being more confident these days, I tend to forget that habit.

the error itself wasn’t to clear at all, and it would be nice if these errors could list the offender.

migration from

service:
entity_id:

to

service:
  target:
    entity_id:

shouldn’t be too difficult. However, the ui shows this:

service: light.turn_on
data:
  color_name: fuchsia
target:
  entity_id: light.bedside_table

if and when extra data is required. Right now, I use the entity_id and color_name (or other parameters) in the data field. Do I understand this correctly then that those 2 should be best kept apart? Entity_id in the target field, and all other data in the data field?

it’s actually

service:
target:
  entity_id:

Also, I’m not making the update myself unless I update the automation or script. I do make the switch for new automations that I create.

Yes, target simply allows users to use entity_id, area, or device_id inside the target. So now you can use any of them for a service call instead of just entity_id.

All other keys/options/attributes (whatever you want to call them) go inside data.

1 Like

ok, thanks.
lastly: in the case of an entity template (until target: came along needed to be in data:), do we now move that under target, or still under data:?

      - service: switch.turn_off
        data:
          entity_id: >
            switch.vijverpomp_{{'links' if now().day % 2 else 'rechts'}}

becomes:

      - service: switch.turn_off
        target:
          entity_id: >
            switch.vijverpomp_{{'links' if now().day % 2 else 'rechts'}}

?

Yes, like the second example.