hi,
stripping all bugs, im puzzled: this template sensor shows Unknown, or nothing as in ‘-’.
since_last_boot_template:
friendly_name: 'Since Last Boot'
value_template: >
{%- set s = states.sensor.since_last_boot.state.split('.')[0] -%}
{{ s }}
Anyone see the error??
Cheers and thanks for looking,
Marius
keithh666
(Keith Hull)
December 6, 2017, 1:03pm
2
Dev tools says it works fine, however I can’t see any error otherwise, assuming you have - platform: sensors: above it.
yes sure, its in an include file with all other small templates:
##########################################################################################
# Template Sensor
# https://home-assistant.io/components/sensor.template/
##########################################################################################
- platform: template
sensors:
day_night:
friendly_name: "Day/Night"
value_template: >-
{% if is_state('sun.sun', 'above_horizon') %}
Day
{% else %}
Night
{% endif %}
entity_picture_template: >-
{% if is_state('sun.sun', 'above_horizon') %}
/local/day.png
{% else %}
/local/night.png
{% endif %}
dag_nacht:
friendly_name: "Dag/Nacht"
value_template: >-
{% if is_state('sun.sun', 'above_horizon') %}
Day
{% else %}
Night
{% endif %}
icon_template: >-
{% if is_state('sun.sun', 'above_horizon') %}
mdi:weather-sunny
{% else %}
mdi:weather-night
{% endif %}
solar_angle:
friendly_name: "Sun Angle"
unit_of_measurement: '°'
value_template: "{{ '%+.1f'|format(states.sun.sun.attributes.elevation) }}"
sun_state:
friendly_name: "Sun State"
value_template: >-
{% if is_state('sun.sun', 'above_horizon') %}
up
{% else %}
down
{% endif %}
nextsunrise:
friendly_name: Next Sunrise
value_template: '{{ as_timestamp(states.sun.sun.attributes.next_rising) | timestamp_custom("%H %M %D") }}'
nextsunset:
friendly_name: Next Sunset
value_template: '{{ as_timestamp(states.sun.sun.attributes.next_setting) | timestamp_custom("%H %M %D") }}'
dayofyear:
friendly_name: 'Day Number'
value_template: '{{ now().strftime("%j") }}'
weekofyear:
friendly_name: 'Week Number'
value_template: '{{ now().strftime("%U") }}'
time_template:
friendly_name: 'Time'
value_template: '{{ as_timestamp(now()) | timestamp_custom("%d/%m %H:%M", True) }}'
since_last_boot_template:
friendly_name: 'Since Last Boot'
value_template: >
{%- set s = states.sensor.since_last_boot.state.split('.')[0] -%}
{{ s }}
battery_telefoon:
friendly_name: Marijns telefoon battery
entity_id: device_tracker.telefoon
unit_of_measurement: '%'
value_template: >-
{%- if states.device_tracker.telefoon.attributes.battery %}
{{ states.device_tracker.telefoon.attributes.battery|round }}
{% else %}
{{ states.sensor.battery_telefoon.state }}
{%- endif %}
icon_template: >
{% set battery_level = states.sensor.battery_telefoon.state|default(0)|int %}
{% set battery_round = (battery_level / 10) |int * 10 %}
{% if battery_round >= 100 %}
mdi:battery
{% elif battery_round > 0 %}
mdi:battery-{{ battery_round }}
{% else %}
mdi:battery-alert
{% endif %}
my dev tools say:
keithh666
(Keith Hull)
December 6, 2017, 3:27pm
4
In the states table in dev tools search for since_last_boot use ctrl-f and type that in, see if there is another one under sensors?
keithh666:
since_last_boot use
nope there isn’t. Ive found a missing - behind the >, but adding that doesn’t change it.
Strangely enough the sensor in the detailed view says its up for 3 hours. just rebooted, and also states uptime in minutes. Nothing in the badge though. Might that be because of the custom ui?
sensor.since_last_boot_template:
icon: mdi:av-timer
state_card_mode: badges
friendly_name: 'Up'
keithh666
(Keith Hull)
December 6, 2017, 3:39pm
6
Seems a likely candidate :), I can’t comment as I don’t use it.
apparently that is not the culprit ;-(((
What if you just try:
value_template: {{ states.sensor.since_last_boot.state.split('.')[0] }}
keithh666
(Keith Hull)
December 6, 2017, 4:03pm
9
Mine shows the above, with the exact code you posted
EDIT: Just realised that might be from system monitor - retrying with that commented out
@VDRainer in dev tools it doesn’t like states however I’ve not tried doing it that way in the code
EDIT: 2 this now works, so system monitor was causing it to not work.
keithh666
(Keith Hull)
December 6, 2017, 4:06pm
10
In the above remove _template and see what that gives.
keithh666
(Keith Hull)
December 6, 2017, 4:30pm
11
Mariusthvdb:
sensor.since_last_boot
What I think is happening is that sensor.since_last_boot is not defined in the first place, I could only get the template to work if system monitor was defined, which in turn creates sensor.since_last_boot
1 Like
keithh666
(Keith Hull)
December 6, 2017, 4:34pm
12
If you put the above in dev-tools->templates what happens?
keithh666:
What I think is happening is that sensor.since_last_boot is not defined in the first place, I could only get the template to work if system monitor was defined, which in turn creates sensor.since_last_boot
of course i had the system monitor declared, but not with type since_last_boot… duh, sometimes
rebooting now, see what gives
–edit–
Bingo!
So this sensor template isn’t a sensor in itself, it is a sensor that reads the output from another entity. Hence the template… tss
what does that do actually? seen it before even copied it with succes not sure what is does to be honest.
even made the custom ui:
its showing the time of the last boot, not the time since last boot though…
and its an hour off
happy tweaking.