Hey all - Haven’t had much luck finding anything to help me with this.
I have a Victron inverter which through MODBUS gives me the state it is in via a number which corresponds to what it is doing. I’d like to convert that number output to the appropriate text to display in lovelace.
Can this be done in the lovelace entity yaml? or can I do it within the sensor before it gets to the lovelace point?
Conditional entity cards are not what I’m after, the sensor is with other sensors on a entity card.
I’m new to this too, but as I understand it, the value_template is there for extracting responses from REST (web services) queries. You just want a template sensor, so follow the examples here:
At quick glance, I think replacing friendly_name with just name and value_template with state should do it.
Hey Guys i am new to Home assistant and i have tried to follow your examples without success.
I have heat pump and the heat pump compressor gives a value of ‘0’ if off and ‘1’ if on.
On the entity card is shows either 0 or 1.
I have tried to copy and modify some of the code examples above and put into the card yaml but no success. Any help would be appreciated.
Here is my code:
type: custom:mushroom-entity-card entity: sensor.heatpump_compressor_status name: Heatpump Compressor icon_color: red icon: mdi:heat-pump state: >- {% if is_state('sensor.heatpump_compressor_status', '0') %} Off {% elif is_state('sensor.heatpump_compressor_status', '1') %} On {% endif %}
And here is the error i get:
At path: state – Expected a value of type never, but received: "{% if is_state('sensor.heatpump_compressor_status', '0') %} Off {% elif is_state('sensor.heatpump_compressor_status', '1') %} On {% endif %}"
That might work, but the iif() function is an if-then-else construction, so it’s not really appropriate for when you have more than 2 possible outputs. Using a dictionary is more efficient than a lot of if-thens.
For my Itho fan I want to replace the precentages, attribuut of my fan.itho_fan, to a text value. My itho does not give me a status of high, medium or low, but only a percentage.
So I created therefore a template sensor like below;
Hi all, while I know enough HA to be dangerous I’m pretty much n00bing it here with value templates…
I am trying to convert a numeric value pulled via SNMP from my UPS, however none of the examples above seem to yield the expected result. If I remove the value_template, it works fine and just reads a value between 1 and 3, but with the value_template tacked on, the sensor just returns blank as if there is no match, even though the value is 2?
While the Yaml checks out, it does not work. Can anybody spot what I’m doing wrong here? Is it because the sensor has not been created at the time I am trying to read it? Is that why it’s failing to read anything out?
I’m a relative new HA user. I get from my Varta energy storage system the status per number back into HA. Now I want instead of the number the correct wording. So I created the following code in the developer tool template:
sensor:
- platform: template
sensors:
Varta_Status_Text:
name: "varta_text"
unit_of_measurement: "State"
value_template: >-
{% set mapper = {
'0' : 'Hochfahren',
'1' : 'Betrieb',
'2' : 'Laden',
'3' : 'Entladen',
'4' : 'Standby',
'5' : 'Fehler',
'6' : 'Service',
'7' : 'Inselbetrieb' } %}
{% set state = states.sensor.vartastatus.state %}
{{ mapper[state] if state in mapper else 'Unknown' }}
Now to my questions, where should this code be, in the configuration.yaml it wouldn’t work.
I am also trying to template enumerations based on numbers and I’m getting odd behaviour. The code is below. Does anyone have any suggestions?
{% set u = (states.sensor.uv.state | int) %}
{% set d = {
0: 'None',
1: 'Low',
2: 'Low',
3: 'Medium',
4: 'Medium',
5: 'Medium',
6: 'High',
7: 'High',
8: 'Very High',
9: 'Very High',
10: 'Very High',
11: 'Extreme',
12: 'Extreme' } %}
{{ d[u] if u in d else 'Unknown' }}
When the state is 0, the template returns Unknown, for some reason, the d[u] returns null.
If I add a new line with {{ d[u] }} the template will return “None None” as expected… when I remove the last line it will return Unknown again… is this a bug or a feature?
UPDATE the issue seems to be the value for key 0. So if I change the ‘None’ value to anything else (currently it’s working with 0: ‘No’), this thing works fine… so it IS a bug