I would like to show in my Lovelace the ink level of my printer with a gauge. It’s work but when my printer is off, I can’t view the level.
So I create a variable with https://github.com/rogro82/hass-variables, and when the printer started, I update the variable level_ink_black with the value of sensor.hp_envy_4520_series_black_ink in an automation. It’s work and I can show the level in Lovelace with Entity Card and the level_ink_black variable.
But I can’t select the variable entity level_ink_black in Gauge card because it’s not a sensor.
So how can I use this variable in Gauge or have you an other solution to have the ink level when printer is off ?
While I really like that variable integration and use it quite a bit I don’t think it is the best to use for what you want.
I would create a template sensor based on your ink level sensor:
sensor:
- platform: template
sensors:
black_ink_memory:
friendly_name: Saved Value of Black Ink
value_template: >
{% if states('sensor.hp_envy_4520_series_black_ink') != 'unavailable' %}
{{ states('sensor.hp_envy_4520_series_black_ink') }}
{% else %}
{{ states('sensor.black_ink_memory') }}
{% endif %}
Since you didn’t specify what the state of your sensor is when you “can’t view the level” you may have to change the test string for your sensor in the template. I assumed it was ‘unavailable’.
I’m beginner in Home assistant, so thank you for your explanation, it’s work perfectly !
I didn’t know it was possible to create sensors. I thought I had to use variable with hass-variables to save a value.
So if I understand you code, it’s create an black_ink_memory sensor. If the value of “sensor.hp_envy_4520_series_black_ink” isn’t unavailable, black_ink_memory sensor save his value. Else black_ink_memory sensor keep his value.
But I don’t understand when value_template is call ? I don’t must create an automation to update the black_ink_memory sensor ?
Also, how can I save the black_ink_memory sensor value when I restart HA ? With hass-variable, there is “restore” param. But it dosen’t work with this sensor.
And is it normal that I can’t find the black_ink_memory sensor in Configuration/Entities page ?
I want the sensor value survive a restart.
When I shutdown my printer, gauge work with sensor.black_ink_memory. But after, when I restart my HA, the sensor.black_ink_memory as “unknown” state. It dosen’t keep his value after restart
So I tested “restore” param like with hass-variables, but it’s not a correct option. Have you a solution please ? It’s the only problem.