From 95dbb9017e5f585f2eb467818271ded3d024395e Mon Sep 17 00:00:00 2001 From: Long Zheng Date: Mon, 6 Jan 2025 21:42:07 +1100 Subject: [PATCH] doc: Simplify Home Assistant sensors, add device_class to allow changing measurement units (#4472) --- website/docs/integrations/home_assistant.md | 263 ++++++++------------ 1 file changed, 97 insertions(+), 166 deletions(-) diff --git a/website/docs/integrations/home_assistant.md b/website/docs/integrations/home_assistant.md index 73c6512c6a..0985868baf 100644 --- a/website/docs/integrations/home_assistant.md +++ b/website/docs/integrations/home_assistant.md @@ -51,8 +51,6 @@ tesla: scan_interval: 3600 mqtt: !include mqtt_sensors.yaml -sensor: !include sensor.yaml -binary_sensor: !include binary_sensor.yaml ``` ### mqtt_sensors.yaml (mqtt: section of configuration.yaml) @@ -185,6 +183,20 @@ Don't forget to replace ``, `` and `- + {% if value == 'P' %} + ON + {% else %} + OFF + {% endif %} + icon: mdi:car-brake-parking + - sensor: name: Power object_id: tesla_power @@ -201,6 +213,7 @@ Don't forget to replace ``, `` and ``, `` and ``, `` and ``, `` and ``, `` and ``, `` and ``, `` and ``, `` and ``, `` and ``, `` and ``, `` and ``, `` and ` - {% if has_value('sensor.tesla_est_battery_range_km') %} - {{ (states('sensor.tesla_est_battery_range_km') | float / 1.609344) | round(2) }} - {% endif %} - - tesla_rated_battery_range_mi: - friendly_name: Rated Range (mi) - unit_of_measurement: mi - icon_template: mdi:gauge - availability_template: "{{ has_value('sensor.tesla_rated_battery_range_km') }}" - value_template: > - {% if has_value('sensor.tesla_rated_battery_range_km') %} - {{ (states('sensor.tesla_rated_battery_range_km') | float / 1.609344) | round(2) }} - {% endif %} - - tesla_ideal_battery_range_mi: - friendly_name: Ideal Range (mi) - unit_of_measurement: mi - icon_template: mdi:gauge - availability_template: "{{ has_value('sensor.tesla_ideal_battery_range_km') }}" - value_template: > - {% if has_value('sensor.tesla_ideal_battery_range_km') %} - {{ (states('sensor.tesla_ideal_battery_range_km') | float / 1.609344) | round(2) }} - {% endif %} - - tesla_odometer_mi: - friendly_name: Odometer (mi) - unit_of_measurement: mi - icon_template: mdi:counter - availability_template: "{{ has_value('sensor.tesla_odometer') }}" - value_template: > - {% if has_value('sensor.tesla_odometer') %} - {{ (states('sensor.tesla_odometer') | float / 1.609344) | round(2) }} - {% endif %} - - tesla_speed_mph: - friendly_name: Speed (MPH) - unit_of_measurement: mph - icon_template: mdi:speedometer - availability_template: "{{ has_value('sensor.tesla_speed') }}" - value_template: > - {% if has_value('sensor.tesla_speed') %} - {{ (states('sensor.tesla_speed') | float / 1.609344) | round(2) }} - {% endif %} - - tesla_elevation_ft: - friendly_name: Elevation (ft) - unit_of_measurement: ft - icon_template: mdi:image-filter-hdr - availability_template: "{{ has_value('sensor.tesla_elevation') }}" - value_template: > - {% if has_value('sensor.tesla_elevation') %} - {{ (states('sensor.tesla_elevation') | float * 3.2808) | round(2) }} - {% endif %} - - tesla_tpms_pressure_fl_psi: - friendly_name: Front Left Tire Pressure (psi) - unit_of_measurement: psi - icon_template: mdi:car-tire-alert - availability_template: "{{ has_value('sensor.tesla_tpms_fl') }}" - value_template: > - {% if has_value('sensor.tesla_tpms_fl') %} - {{ (states('sensor.tesla_tpms_fl') | float * 14.50377) | round(2) }} - {% endif %} - - tesla_tpms_pressure_fr_psi: - friendly_name: Front Right Tire Pressure (psi) - unit_of_measurement: psi - icon_template: mdi:car-tire-alert - availability_template: "{{ has_value('sensor.tesla_tpms_fr') }}" - value_template: > - {% if has_value('sensor.tesla_tpms_fr') %} - {{ (states('sensor.tesla_tpms_fr') | float * 14.50377) | round(2) }} - {% endif %} - - tesla_tpms_pressure_rl_psi: - friendly_name: Rear Left Tire Pressure (psi) - unit_of_measurement: psi - icon_template: mdi:car-tire-alert - availability_template: "{{ has_value('sensor.tesla_tpms_rl') }}" - value_template: > - {% if has_value('sensor.tesla_tpms_rl') %} - {{ (states('sensor.tesla_tpms_rl') | float * 14.50377) | round(2) }} - {% endif %} - - tesla_tpms_pressure_rr_psi: - friendly_name: Rear Right Tire Pressure (psi) - unit_of_measurement: psi - icon_template: mdi:car-tire-alert - availability_template: "{{ has_value('sensor.tesla_tpms_rr') }}" - value_template: > - {% if has_value('sensor.tesla_tpms_rr') %} - {{ (states('sensor.tesla_tpms_rr') | float * 14.50377) | round(2) }} - {% endif %} - - tesla_active_route_distance_to_arrival_km: - friendly_name: Active route distance to arrival (km) - unit_of_measurement: km - icon_template: mdi:map-marker-distance - availability_template: "{{ has_value('sensor.tesla_active_route_distance_to_arrival_mi') }}" - value_template: > - {% if has_value('sensor.tesla_active_route_distance_to_arrival_mi') %} - {{ (states('sensor.tesla_active_route_distance_to_arrival_mi') | float * 1.609344) | round(2) }} - {% endif %} -``` - -### binary_sensor.yaml (binary_sensor: section of configuration.yaml) - -```yml title="binary_sensor.yaml" -- platform: template - sensors: - tesla_park_brake: - friendly_name: Parking Brake - icon_template: mdi:car-brake-parking - value_template: >- - {% if is_state('sensor.tesla_shift_state', 'P') %} - ON - {% else %} - OFF - {% endif %} -``` - ### ui-lovelace.yaml The below is the Lovelace UI configuration used to make the example screenshot above. You will obviously want to configure this to your liking, however the example contains all of the sensors and values presented via MQTT and could be used as the basis of UI configuration. @@ -869,14 +814,10 @@ views: name: Shifter State - entity: sensor.tesla_speed name: Speed - - entity: sensor.tesla_speed_mph - name: Speed (MPH) - entity: sensor.tesla_heading name: Heading - entity: sensor.tesla_elevation - name: Elevation (m) - - entity: sensor.tesla_elevation_ft - name: Elevation (ft) + name: Elevation - entity: binary_sensor.tesla_locked name: Locked - entity: binary_sensor.tesla_sentry_mode @@ -901,20 +842,12 @@ views: name: Preconditioning - entity: sensor.tesla_odometer name: Odometer - - entity: sensor.tesla_odometer_mi - name: Odometer (miles) - - entity: sensor.tesla_est_battery_range_km - name: Battery Range (km) - - entity: sensor.tesla_est_battery_range_mi - name: Estimated Battery Range (mi) - - entity: sensor.tesla_rated_battery_range_km - name: Rated Battery Range (km) - - entity: sensor.tesla_rated_battery_range_mi - name: Rated Battery Range (mi) - - entity: sensor.tesla_ideal_battery_range_km - name: Ideal Battery Range (km) - - entity: sensor.tesla_ideal_battery_range_mi - name: Ideal Battery Range (mi) + - entity: sensor.tesla_est_battery_range + name: Battery Range + - entity: sensor.tesla_rated_battery_range + name: Rated Battery Range + - entity: sensor.tesla_ideal_battery_range + name: Ideal Battery Range - entity: sensor.tesla_battery_level name: Battery Level - entity: sensor.tesla_usable_battery_level @@ -959,10 +892,8 @@ views: name: Active Route Destination - entity: sensor.tesla_active_route_energy_at_arrival name: Active Route Energy at Arrival - - entity: sensor.tesla_active_route_distance_to_arrival_km - name: Active Route Distance to Arrival (km) - - entity: sensor.tesla_active_route_distance_to_arrival_mi - name: Active Route Distance to Arrival (mi) + - entity: sensor.tesla_active_route_distance_to_arrival + name: Active Route Distance to Arrival - entity: sensor.tesla_active_route_minutes_to_arrival name: Active Route Minutes to Arrival - entity: sensor.tesla_active_route_traffic_minutes_delay