-
Notifications
You must be signed in to change notification settings - Fork 31
Implementing Dynamic Vehicle Images in Home Assistant for Ultra Vehicle Card
This guide will walk you through the process of implementing dynamic vehicle images in Home Assistant for use with the Ultra Vehicle Card. By following these steps, you'll be able to create sensors that change their entity picture based on the status of various vehicle components, allowing you to display different images for open and closed states, as well as a main image when everything is closed.
- Home Assistant installed and running
- Basic knowledge of YAML configuration
- Access to your Home Assistant configuration files
- Image files for each state of your vehicle components (e.g.,
front_left_door_open.png
,front_left_door_closed.png
, etc.) - A main image of your vehicle when all components are closed (e.g.,
vehicle_closed.png
)
- Create or obtain PNG images for each state of your vehicle components (open and closed).
- Create or obtain a main image of your vehicle with all components closed.
- Place these images in your Home Assistant
config/www/
directory. This directory is accessible via the/local/
URL in Home Assistant.
- Open your Home Assistant configuration file (usually
configuration.yaml
). - Add the following template sensor configuration:
template:
- sensor:
- name: "Vehicle Image"
state: "closed"
attribute_templates:
entity_picture: >
{% if is_state('binary_sensor.front_left_door', 'on') %}
/local/images/front_left_door_open.png
{% elif is_state('binary_sensor.front_right_door', 'on') %}
/local/images/front_right_door_open.png
{% elif is_state('binary_sensor.back_left_door', 'on') %}
/local/images/back_left_door_open.png
{% elif is_state('binary_sensor.back_right_door', 'on') %}
/local/images/back_right_door_open.png
{% elif is_state('binary_sensor.trunk', 'on') %}
/local/images/trunk_open.png
{% elif is_state('binary_sensor.hood', 'on') %}
/local/images/hood_open.png
{% elif is_state('binary_sensor.fuel_door', 'on') %}
/local/images/fuel_door_open.png
{% elif is_state('binary_sensor.front_left_window', 'on') %}
/local/images/front_left_window_open.png
{% elif is_state('binary_sensor.front_right_window', 'on') %}
/local/images/front_right_window_open.png
{% elif is_state('binary_sensor.back_left_window', 'on') %}
/local/images/back_left_window_open.png
{% elif is_state('binary_sensor.back_right_window', 'on') %}
/local/images/back_right_window_open.png
{% else %}
/local/images/vehicle_closed.png
{% endif %}
- Save the configuration file.
- After saving the configuration, restart Home Assistant to apply the changes.
- You can do this from the Home Assistant web interface by navigating to Configuration > Server Controls and clicking on "Restart" under the Server Management section.
- Once Home Assistant has restarted, go to the States page in the Developer Tools.
- Search for the newly created sensor (
sensor.vehicle_image
). - Verify that the
entity_picture
attribute of the sensor is the correct image path based on the current state of your vehicle's components.
- Open the configuration for your Ultra Vehicle Card.
- Set the "Entity" to
sensor.vehicle_image
. - Make sure the card is configured to use the
entity_picture
attribute for displaying images.
The template sensor we've created (sensor.vehicle_image
) works as follows:
- The sensor's state is always set to "closed". This state isn't used for the image display but could be useful for other automations.
- The
entity_picture
attribute is dynamically set based on the state of various binary sensors representing your vehicle's components. - The template checks each component in a specific order. The first open component it finds determines the image that will be displayed.
- If all components are closed (i.e., none of the 'if' conditions are met), it displays the main vehicle image (
vehicle_closed.png
).
You can customize this setup in several ways:
- Change the order of the checks in the template to prioritize certain components.
- Add more components by adding more conditions to the template.
- Use different images for different states or components.
If you encounter issues:
- Check that your binary sensors (e.g.,
binary_sensor.front_left_door
) exist and are working correctly. - Ensure that the image paths in the template sensor match the actual locations of your images in the
www
directory. - Verify that the image files have the correct permissions for Home Assistant to access them.
- If the Ultra Vehicle Card isn't displaying the image, make sure it's configured to use the
entity_picture
attribute.
You have now set up a dynamic vehicle image sensor in Home Assistant for use with the Ultra Vehicle Card. This sensor will automatically update to show the correct image based on the state of your vehicle's components, providing a more interactive and informative display. When all components are closed, it will show the main vehicle image.
Remember to adjust the sensor names and image paths as needed to match your specific setup and image filenames.