Hey there,
I’m completly new to the automation stuff and home assistant.
I’m Using an standart Gauge to Display the CPU-Load, Temperatur and some other stuff from my computer. But when the Computer is turned off it just displays “Entity not available”
Instead of that i want the Card to display the Value 0.
Okay, I think I need to create an Template for that. I know it has to look something like that:
Not sure what happened there. I actually had )}" originally and thought I had corrected it. I obviously stuffed the edit up somehow too. Thanks for pointing out he fix.
Again, thank you very much. Your templates helped me to understand the syntax a little bit more. I was even able to create an own script after your help
I noticed someone liked the solution above. However it is now out of date due to changes in the way home assistant deals with defaults. You should now use:
Hello all, I have a similar question with a twist.
I have created a sensors.yaml file that contains some template sensors mostly for conversion purposes for my solar panel system. Needing to change value scales.
As you can see this converts the sensor.solarnet_power_photovoltaics from KW to W.
However sometimes when there are prolonged periods of darkness (I live in the high north), the sensor becomes unavailable which messes up some calculations.
In the developer tools templating section, I followed an example from a previous post and it the result is 0
state: "{{ 0 if states('sensor.solarnet_power_photovoltaics') == 'unavailable' else states('sensor.solarnet_power_photovoltaics') }}
So my question is how can i integrate that in my existing code? Adding it as a line after gives me an error.
state: "{{ 0 if states('sensor.solarnet_power_photovoltaics') == 'unavailable' else states('sensor.solarnet_power_photovoltaics') }}
Hi @all.
What should the code look like if the sensor contains two variables and then a specific value should be displayed?
In my case, a “0” should be displayed for “unavailable” and a “0” should also be displayed for “-1”.
Here is my attempt, but it doesn’t work:
{{ "0" if states('sensor.aeg_waschtrockner_td1_timetoend') == '-1' or "0" if states('sensor.aeg_waschtrockner_td1_timetoend') == 'unavailable' else states('sensor.aeg_waschtrockner_td1_timetoend') }}
If the value is 0 you can just output the value, no need to test for 0 and replace it with 0. And you can replace the unavailable state with zero using a default value for a float filter so you really only have one test (if ‘-1’).
state: >
{{ 0 if is_state('sensor.aeg_waschtrockner_td1_timetoend', '-1')
else states('sensor.aeg_waschtrockner_td1_timetoend')|float(0) }}
Now I have another challenge, this sensor displays text, but when the machine is switched off, then the value of the sensor is " " (no content)
How do I get the “no content” to display a defined text and when the machine is running, the text from the sensor?
Here is my attempt so far:
{{ "keine" if states('sensor.aeg_waschtrockner_td1_cyclephase') == '' or "keine" if states('sensor.aeg_waschtrockner_td1_cyclephase') == 'unavailable' else states('sensor.aeg_waschtrockner_td1_cyclephase') }}