Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: fix Home Assistant MQTT sensor JSON templates warnings #4257

Merged

Conversation

longzheng
Copy link
Contributor

@longzheng longzheng commented Oct 12, 2024

Fixes #4247

More gracefully handles teslamate/cars/1/active_route topic JSON when the car is not routing, the json_attributes_template would cause a Home Assistant warning since we're trying to access properties on the JSON that aren't there.

MQTT topic active_route

{"error":"No active route available"}

Home Assistant logs

Oct 07 15:10:43 iot2 homeassistant[107792]: 2024-10-07 15:10:43.127 WARNING (MainThread) [homeassistant.components.mqtt.mixins] TypeError: Object of type LoggingUndefined is not JSON serializable rendering template for entity 'device_tracker.tesla_active_route_location', template: '{{ value_json.location | tojson }}' and payload: {"error":"No active route available"}
Oct 07 15:10:43 iot2 homeassistant[107792]: 2024-10-07 15:10:43.127 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'destination' when rendering '{{ value_json.destination }}'
Oct 07 15:10:43 iot2 homeassistant[107792]: 2024-10-07 15:10:43.127 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'energy_at_arrival' when rendering '{{ value_json.energy_at_arrival }}'
Oct 07 15:10:43 iot2 homeassistant[107792]: 2024-10-07 15:10:43.128 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'miles_to_arrival' when rendering '{{ value_json.miles_to_arrival }}'
Oct 07 15:10:43 iot2 homeassistant[107792]: 2024-10-07 15:10:43.128 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'minutes_to_arrival' when rendering '{{ value_json.minutes_to_arrival }}'
Oct 07 15:10:43 iot2 homeassistant[107792]: 2024-10-07 15:10:43.128 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'traffic_minutes_delay' when rendering '{{ value_json.traffic_minutes_delay }}'

Also fix other template sensor errors mentioned in #4247 (comment) which are unrelated to the active route error but a similar issue where the template reference other MQTT sensor numeric values which may be invalid/unavailable, which causes a warning when trying to use math expressions on.

Copy link

netlify bot commented Oct 12, 2024

Deploy Preview for teslamate ready!

Name Link
🔨 Latest commit d6835bb
🔍 Latest deploy log https://app.netlify.com/sites/teslamate/deploys/670e1faec4a85600088b50fd
😎 Deploy Preview https://deploy-preview-4257--teslamate.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@JakobLichterfeld JakobLichterfeld added the kind:documentation Adds or improves documentation label Oct 12, 2024
@longzheng longzheng changed the title Fix Home Assistant active route MQTT sensor JSON templates Fix Home Assistant MQTT sensor JSON templates warnings Oct 13, 2024
Conditionally convert values if the sensor actually has a value, to prevent converting invalid non-numeric values
@JakobLichterfeld JakobLichterfeld changed the title Fix Home Assistant MQTT sensor JSON templates warnings doc: fix Home Assistant MQTT sensor JSON templates warnings Oct 13, 2024
@JakobLichterfeld JakobLichterfeld changed the title doc: fix Home Assistant MQTT sensor JSON templates warnings docs: fix Home Assistant MQTT sensor JSON templates warnings Oct 13, 2024
@swiffer
Copy link
Contributor

swiffer commented Oct 13, 2024

tested successfully here (updated mqtt_sensors.yaml, restarted home_assistant, no errors in logs).

Copy link
Collaborator

@brianmay brianmay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but a bit puzzled about the changes from multiple to divide in some places.

website/docs/integrations/home_assistant.md Outdated Show resolved Hide resolved
website/docs/integrations/home_assistant.md Outdated Show resolved Hide resolved
@longzheng
Copy link
Contributor Author

@JakobLichterfeld not sure why the CI failed, can you retry please

@JakobLichterfeld
Copy link
Collaborator

@JakobLichterfeld not sure why the CI failed, can you retry please

Yeah, GitHub Runners have been slow yesterday and caused lots of failures, not related to your PR. Today it runs fine.

@JakobLichterfeld JakobLichterfeld merged commit 123f7ab into teslamate-org:master Oct 19, 2024
19 of 23 checks passed
JakobLichterfeld pushed a commit that referenced this pull request Oct 19, 2024
* Fix Home Assistant active route MQTT sensor JSON templates

More gracefully handles JSONs with error (not actively routing)

* Fix tesla_active_route_distance_to_arrival_km sensor

* Fix template sensors

Conditionally convert values if the sensor actually has a value, to prevent converting invalid non-numeric values

* Fix copy/paste mistakes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:documentation Adds or improves documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

home-assistant template errors
4 participants