Long-term user of HomeSeer and experienced Python - but total newbie for HA and jinja is still pretty Greek. I’ve successfully captured a web hook from a GPS tracker. The JSON output is:
{
"EventType": "gps_report",
"GPS_Report": {
"ReportID": "Xvfq6nsB8mdQyQS2s92Z",
"Accuracy": 20,
"CreateTime": "2021-08-27T23:20:50Z",
"DeviceID": 49841,
"DeviceState": "NotMoving_NotCharging",
"HDOP": 4.15,
"Heading": 107,
"Latitude": 26.95457,
"Longitude": -81.89468,
"PositionSource": "gps",
"ReceivedTime": "2021-08-27T23:21:50Z",
"ReportingFrequency": "1d|10m Premium",
"ReportReason": "MovementChange",
"RSSI": -75,
"Speed": 107,
"Temperature": 22,
"Voltage": 4.15,
"VoltagePercent": 98
},
"Mode": "live"
}
If I display {{ trigger.json.GPS_Report.DeviceID }} I get the 5 digit string I expect. What I need to do is translate the 5 digit code to a vehicle name (text). However, if I execute
{% set vehicle_id = {'Jeep':'12345', 'Volvo':'23456', 'Trailer':'34567'} %}
{% for v, i in vehicle_id.items() %}
{% if i == trigger.json.GPS_Report.DeviceID %}
Vehicle = {{ v }}
{% endif %}
{% endfor %}
I get the null string. If I put double braces around the json element {{ trigger.json.GPS_Report.DeviceID }} I get the error
Message malformed: template value should be a string for dictionary value @ data['action'][2]['data']
Assistance would be appreciated. If there is an easier way, that guidance would be appreciated as well. TIA