If I were to remove the if then else statements and the entity_id line I am sure if would work as some other users have this set up so I am sure this is what is causing the issue.
If I remove the entity_id line on its own, it throws an error.
A template will always result in a single string, so what you are trying to do is not possible with a template, because you are trying to create a dictionary.
You took what I had suggested (in the other thread) and applied it in an unexpected way. I was going to ask “Did that actually work?” and I guess this thread serves as the answer.
You’re using templates to generate YAML statements and that’s not how they’re meant to be used.
You’ll have to explain what you’re trying to do because, even without the templates, I don’t understand how this is a valid YAML let alone a valid entity_id:
Ok so I have an automation with a webhook trigger that my car tracking system posts to.
It posts 3 different types of json messages.
All of the messages contain one variable that is the same called pack_id.
This is the identifier of the message.
1 = a position change message
3 = an ignition status change message
22 = a driver behaviour event message
If it was all included in the same pack, the action would be as @Tinkerer showed me in another topic. here And here.
Basically I wouldn’t need the if then else statements and my action would be the same as @Tinkerer’s.
So in a nutshell:
Incoming webhook with json body payload
read pack_id
if the pack_id = 1 then create/update entity with attributes lat, lng, speed, position_gmt.
if the pack_id = 3 then create/update entity with attributes ignition, ignition_gmt
and so on…
Yes I currently have it working by means of a sensor with a different API, however it is a pull API and the data only refreshed every 60 seconds. O wanted to use the push API so the data is pushed to HA in real time.
Also in addition some of the features in the push API aren’t available in the pull API so currently I am.missong some data.
I suppose I could create a blank entity using sensor then use another method in the automation to update the attributes - is this what you meant?