Create a Template Sensor from Attribute

Hi,

i am trying to create a sensor via the template platform from the Xiaomi Mi Robot Vacuum Component.
So I can see it in more detail without clicking on it.
As example just start the spot cleaning, no need to first click in the object itself.

So far, I tried this, but it is not getting any status information:

battery_level:
    friendly_name: Charging State
    value_template: '{{ states.vaccum.eve.attributes["battery level"] }}'

Any idea what is wrong ?

I doubt a dictionary key in home assistant would have an attribute with a space in its name. I could be wrong but that looks off. I would also expect this to work, if battery_level is the correct attribute:

'{{ states.vaccum.eve.attributes.battery_level }}'

you may face a simple typo error

Just replace “vaccum” with “vacuum”

{{ states.vacuum.eve.attributes.battery_level }}

Thanks guys,

it is a mix of booth, the typo and the space…

battery_level:
    friendly_name: Charging State
    value_template: '{{ states.vacuum.eva.attributes.battery_level }}'

This is working fine now !

I’m trying to create a template sensor from a motion event triggered by a Doorbird station. The goal is to display the show_last_changed attribute of a motion sensor in a glance card. However, the timestamp of the motion is in the Doorbird event. The doorbird sends an event to HA like:
Event 0 fired 10:29 PM:
{
“event_type”: “doorbird_front_gate_motion”,
“data”: {
“timestamp”: “2019-11-19T06:29:31.868412+00:00”,
“live_video_url”: “http://station_name:[email protected]:80/bha-api/video.cgi”,
“live_image_url”: “http://station_name:[email protected]:80/bha-api/image.cgi”,
“rtsp_live_video_url”: “rtsp://station_name:[email protected]:554/mpeg/media.amp”,
“html5_viewer_url”: “http://station_name:[email protected]:80/bha-api/view.html
},
“origin”: “LOCAL”,
“time_fired”: “2019-11-19T06:29:31.868702+00:00”,
“context”: {
“id”: “your_doorbird_ID”,
“parent_id”: null,
“user_id”: null
}

I used the following in my sensors.yaml file:

  • platform: template
    sensors:
    doorbird_front_door_motion:
    value_template: {{state_attr(event.doorbird_front_door_motion, timestamp) }}
    friendly_name: ‘Front Gate Motion’

I get the following error:
Error loading /config/configuration.yaml: invalid key: “OrderedDict([(‘state_attr(event.doorbird_front_door_motion’, None), (‘timestamp)’, None)])”
in “/config/sensors.yaml”, line 19, column 0

try this:

* platform: template
sensors:
doorbird_front_door_motion:
value_template: "{{state_attr(event.doorbird_front_door_motion, timestamp) }}"
friendly_name: ‘Front Gate Motion’