Thank you for this!
I’m very new to HA, but I have got the “sensor.surepet_connect” to give a Json output like this:
{"Kakan": "Inside","Cappuccino": "Inside","avg_battery": 24, "battery": 24,"flap_online": true,"hub_online": true,"lock_status": "Keep pets in","locked": true}
And that’s all good, so the “sensor” is working.
So in my configuration.yaml
I have added this so far under sensor:
# Sure PetCare Flap Door
- platform: sure_petflap
username: !secret surepet_user
password: !secret surepet_pass
So far so good, I get the Json above, so I assume it works.
Then I try to add your “Template code” underneath (in the configuration.yaml (is that correct??))
So it looks like this (have two cats…):
# Sure PetCare Flap Door
- platform: sure_petflap
username: !secret surepet_user
password: !secret surepet_pass
- platform: template
sensors:
Kakan_status:
friendly_name: "Kakans Status"
value_template: "{{ state_attr('sensor.surepet_connect', 'Kakan') }}"
Cappuccino_status:
friendly_name: "Cappuccinos Status"
value_template: "{{ state_attr('sensor.surepet_connect', 'Cappuccino') }}"
flap_battery_status:
friendly_name: "Sure Flap Battery"
value_template: "{{ state_attr('sensor.surepet_connect', 'battery') }}"
unit_of_measurement: '%'
flap_batterystatus:
friendly_name: Sure Flap Battery
value_template: >
{% if is_state('sensor.surepet_connect', 'unknown') %}
110
{% else %}
{{ states.sensor.surepet_connect.attributes["battery"] | float}}
{% endif %}
icon_template: >
{% set battery_level_xod1 = states.sensor.surepet_connect.attributes.battery|default(0)|int %}
{% set battery_round_xod1 = (battery_level_xod1 / 10) |int * 10 %}
{% if battery_round_xod1 >= 100 or is_state('sensor.surepet_connect', 'unknown') %}
mdi:battery
{% elif battery_round_xod1 > 0 %}
mdi:battery-{{ battery_round_xod1 }}
{% else %}
mdi:battery-charging-wireless-outline
{% endif %}
unit_of_measurement: '%'
- platform: history_stats
name: Kakans outside time (today)
entity_id: sensor.Kakan_status
state: 'Outside'
type: time
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
- platform: history_stats
name: Kakans trips outside (today)
entity_id: sensor.Kakan_status
state: 'Outside'
type: count
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
- platform: history_stats
name: Kakan outside (yesterday)
entity_id: sensor.Kakan_status
state: 'Outside'
type: time
end : '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
duration:
hours: 24
- platform: history_stats
name: Kakans trips outside (yesterday)
entity_id: sensor.Kakan_status
state: 'Outside'
type: count
end : '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
duration:
hours: 24
binary_sensor:
- platform: template
sensors:
lock_status:
friendly_name: "Sure Flap"
device_class: lock
value_template: "{{ not states.sensor.surepet_connect.attributes.locked}}"
icon_template : >
{% if states.sensor.surepet_connect.attributes.locked %}
mdi:lock
{% else %}
mdi:lock-open
{% endif %}
flap_status:
friendly_name: "Flap online Status"
device_class: connectivity
value_template: "{{ states.sensor.surepet_connect.attributes.flap_online }}"
icon_template : >
{% if states.sensor.surepet_connect.attributes.flap_online %}
mdi:wifi
{% else %}
mdi:wifi-off
{% endif %}
hub_status:
friendly_name: "Hub online Status"
device_class: connectivity
value_template: "{{ states.sensor.surepet_connect.attributes.hub_online }}"
icon_template : >
{% if states.sensor.surepet_connect.attributes.hub_online %}
mdi:wifi
{% else %}
mdi:wifi-off
{% endif %}
But when I do “check config” I get’s lot’s of errors:
Invalid config for [sensor.template]: invalid slug Kakan_status (try kakan_status) for dictionary value @ data['sensors']. Got OrderedDict([('Kakan_status', OrderedDict([('friendly_name', 'Kakans Status'), ('value_template', "{{ state_attr('sensor.surepet_connect', 'Kakan') }}")])), ('Cappuccino_status', OrderedDict([('friendly_name', 'Cappuccinos Status'), ('value_template', "{{ state_attr('sensor.surepet_connect', 'Cappuccino') }}")])), ('flap_battery_status', OrderedDict([('friendly_name', 'Sure Flap Battery'), ('value_template', "{{ state_attr('sensor.surepet_connect', 'battery') }}"), ('unit_of_measurement', '%'.... (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.template/
I tried to understand the documentation, but coming from the world of LUA in a Fibaro-box I have to learn. I’m not sure where to start looking for “errors”. Or what I have missed/messed up.
As soon as I remove the “template” stuff, it works.
Can you just point out the basics?
Thank you.