It is working now.
Thanks for the help.
Just curious, how to change the icon of the template sensor into battery icon?
Currently it is an eye icon.
Thanks.
icon: mdi:battery
in the config…
Not working.
Have config error after added icon: mdi:battery
, as per screenshot below:
show your code
Here is my code:
- platform: template
sensors:
door_sensor_battery_level:
friendly_name: "Door Sensor Battery Level"
entity_id: binary_sensor.openclose_13
unit_of_measurement: '%'
value_template: "{{ state_attr('binary_sensor.openclose_13', 'battery_level') }}"
icon: mdi:battery
From the docs…
icon_template: mdi:battery
Seems you need an icon template
device_class
(device_class)(Optional)Sets the class of the device, changing the device state and icon that is displayed on the UI (see below). It does not set the unit_of_measurement
.
Default value: None
As was already suggested, use device_class: battery
Yes, it is working perfectly now.
Thanks for the great help!
Is the definition of a custom sensor template the ONLY way to show said attributes in a card?
I find that going to the configuration and to introduce a new virtual sensor for each attribute is quite involved.
I’m still trying to figure all this out myself. But I found you can call the attribute directly by the card using service calls.
Here’s what I have so far for a conditional card during weather events.
card:
color: red
color_type: card
entity: sensor.warnings
layout: icon_state
show_name: false
show_state: true
size: 100%
styles:
card:
- height: 60px
grid:
- grid-template-areas: '"i s" "n n" "l l"'
- grid-template-columns: 20% 1fr
- grid-template-rows: 1fr min-content min-content
state:
- text-transform: uppercase
- font-weight: bold
- justify-self: start
tap_action:
action: call-service
service: browser_mod.popup
service_data:
card:
content: '{{ state_attr(''sensor.warnings'', ''alert detail'') }}'
type: markdown
deviceID:
- this
title: Alert Details
type: 'custom:button-card'
conditions:
- entity: sensor.bad_weather
state_not: 'False'
type: conditional
This works as a charm also for my Eurotronic Zigbee thermostat. Please note that entity_id is now deprecated, so you can just skip it.
- platform: template
sensors:
thermostat_ronald_current_temp:
friendly_name: "Thermostat Ronald current temp"
unit_of_measurement: "°C"
value_template: "{{ state_attr('climate.thermostat_31', 'current_temperature') }} "
thermostat_ronald_temp:
friendly_name: "Thermostat Ronald temp"
unit_of_measurement: "°C"
value_template: "{{ state_attr('climate.thermostat_31', 'temperature') }} "
I am in the process of doing this, can you please confirm if the icon changes due to the battery % or do we need to show this a template for this? with an IF function.
I am trying to use the new energy dashboard with my vesync switches. Here is one of the sensors:
switch.washer
attributes:
current_power_w: 1.67
today_energy_kwh: 12.2886
voltage: 123.13
weekly_energy_total: 0.63
monthly_energy_total: 0.3915
yearly_energy_total: 23.8708
friendly_name: Washer
I am trying to create a template sensor for energy (kWh) and have the following within my template sensors config:
laundry_energy_today:
friendly_name: "Landry Energy Today"
entity_id: switch.washer
unit_of_measurement: 'kWh'
value_template: "{{ state_attr('switch.washer', 'today_energy_kwh') }}"
But I am getting a deprecated alert on using the switch as the entity_id.
Is there any other way I can get my smart plugs into my energy dashboard from a switch entity?
The entity_id
option was deprecated many versions ago. You can simply remove it. However, the resulting Template Sensor will not be compatible with the Energy integration.
Why? Because it lacks this:
state_class: measurement
However, you cannot simply add that to the Template Sensor you posted because it uses the old-style method of configuring a Template Sensor (what is now known as the ‘legacy’ method). The ‘legacy’ style of Template Sensor doesn’t support the state_class
option.
You have to define the Template Sensor using the new ‘modern’ format as shown in the documentation for the Template integration. It supports the state_class
option.
There’s an example posted here with additional information:
Do you put this under the yaml configuration file? I have something similar like the below that I cannot get to pull up as a sensor in any card.
template:
sensor:
- inside_humidity:
friendly_name: "Carrier Inside Humidity"
entity_id: climate.bedrooms_hallway_1
unit_of_measurement: '%'
value_template: "{{ state_attr('climate.bedrooms_hallway_1', 'current_humidity') }}"
``
Check the documentation link that was provided earlier:
It’ll give you the supported variables. friendly_name
is not one of them
Otherwise your code looks ok at first glance…
Still cannot get this to work. I am not sure what the secret is here…
sensor:
- platform: template
sensors:
inside_humidity:
name: "Carrier Inside Humidity"
unit_of_measurement: "%"
state: "{{ state_attr('climate.bedrooms_hallway_1', 'current_humidity') }}"
This is the error I get:
Invalid config for [sensor.template]: [name] is an invalid option for [sensor.template]. Check: sensor.template->sensors->inside_humidity->name. (See ?, line ?).
You are attempting to create a legacy Template Sensor but with the options of a modern Template Sensor. Pick one style or the other but don’t mix the two together like you have done.
This is legacy style:
sensor:
- platform: template
sensors:
inside_humidity:
friendly_name: "Carrier Inside Humidity"
unit_of_measurement: "%"
value_template: "{{ state_attr('climate.bedrooms_hallway_1', 'current_humidity') }}"
This is modern style:
template:
- sensor:
- name: Inside Humidity
unit_of_measurement: "%"
state: "{{ state_attr('climate.bedrooms_hallway_1', 'current_humidity') }}"
perfect. working now.