Im using a code that tell me when my washingmachine is finished but a got att warning in logs.
What to add and where?
Tried to add {{ states(‘tvattmaskin_energi’)|round(default=0) }} above but still renders in warning.
The Warning:
Template warning: ‘float’ got invalid input ‘unavailable’ when rendering template ‘{% if states.sensor.tvattmaskin_energi.state | float > 3.0 %} {{ “Running” }} {% elif states.sensor.tvattmaskin_energi.state | float > 1 %} {{ “On” }} {% else %} {{ “Off” }} {% endif %}’ but no default was specified. Currently ‘float’ will return ‘0’, however this template will fail to render in Home Assistant core 2021.12
The Code:
homeassistant:
customize_glob:
"*tvattmaskin*":
icon: mdi:washing-machine
input_text:
tvattmaskin_utokad_status:
name: 'Tvättmaskin Utökad Status'
initial: Off
sensor:
- platform: template
sensors:
tvattmaskin_status:
friendly_name: 'Tvättmaskin Status'
value_template: >
{% if states.sensor.tvattmaskin_energi.state | float > 3.0 %}
{{ "Running" }}
{% elif states.sensor.tvattmaskin_energi.state | float > 1 %}
{{ "On" }}
{% else %}
{{ "Off" }}
{% endif %}
tvattmaskin_info:
friendly_name: 'Tvättmaskin Info'
#entity_id: sensor.time
value_template: >
{%- macro as_formatted_elapsed_time(now, other_date_time) %}
{% set duration = as_timestamp(now) - as_timestamp(other_date_time) %}
{% set seconds = (duration % 60) | int %}
{% set minutes = ((duration / 60) | int) % 60 %}
{% set hours = (duration / 3600) | int %}
{{ [hours, "hours", minutes, "minutes", seconds, "seconds"] | join(' ') }}
{%- endmacro %}
{% if states.input_text.tvattmaskin_utokad_status.state == "Running" %}
Tvättmaskinen körd i: {{ as_formatted_elapsed_time(now(), states.input_text.tvattmaskin_utokad_status.last_changed)}}
{% elif states.input_text.tvattmaskin_utokad_status.state == "On_After_Running" %}
Kläder kvar i tvättmaskinen i: {{ as_formatted_elapsed_time(now(), states.input_text.tvattmaskin_utokad_status.last_changed)}}
{% elif states.input_text.tvattmaskin_utokad_status.state == "On_After_Off" %}
{{ "Tvättmaskinen är redo att startas" }}
{% else %}
{{ "Tvättmaskinen är avstängd" }}
{% endif %}
automation:
- id: '1556314846684'
alias: Uppdatera Tvättmaskin Info
initial_state: true
trigger:
platform: state
entity_id: sensor.tvattmaskin_status
action:
- service: input_text.set_value
data_template:
entity_id: input_text.tvattmaskin_utokad_status
value: >
{% if trigger.to_state.state == "Running" %}
{{ "Running" }}
{% elif trigger.to_state.state == "On" and trigger.from_state.state == "Running" %}
{{ "On_After_Running" }}
{% elif trigger.to_state.state == "On" and trigger.from_state.state == "Off" %}
{{ "On_After_Off" }}
{% else %}
{{ "Off" }}
{% endif %}