can helper entities work with custom button-card?
i have this card:
type: custom:button-card
color_type: card
entity: sensor.running_water
name: running water indicator
tap_action:
action: more-info
state:
- value: 'on'
color: blue
icon: mdi:water-alert
name: water are running
styles:
card:
- animation: rotating 5s
- operator: default
color: black
icon: mdi:faucet
name: nothing is leaking
size: 10%
it used to work great with a “template sensor” that i made from a water counter entity on an esp8266. i dont really care about measuring the amount of water that goes trough it, just wanna know when they r running.
so i made a template sensor to return “on” of “off” depending on the state with this code:
"{% if states('sensor.water_flow_meter') | float > 0%} on {% elif states('sensor.water_flow_meter') | float < 0.01%} off {% endif %}"
and all worked fine.
the sensor was not connected for a while, and after reconnecting it, i recreated the entity with a “helper” from the “template” kind. the new entity name is : “sensor.running_water”
the new sensor and entity works fine on its own, and shows the right “no/off” states.
however, the animation of the custom button-card does not work with the new “helper” entity.
i tried looking over the custom button-card integration, but my coding skills are no match for whats going on there, and i couldnt figure it out.
any pointers will be gr8.
Yes, Custom button card works with Template helpers, but you probably want something like:
styles:
icon:
- animation: rotating 5s infinite
The way you had it configured, the whole card would rotate once.
thanks for the quick answer and tip. usually, i use it like you suggested. in this case, since its gonna be for UNWANTED leaks, i rather have the whole thing spin…
however, as mentioned, the problem is that the animation doesnt work for the “helper” entity (works great for any others), and as i said, the helper entity works great on its own in any other card or combination, but not with the code above for the “custom button”.
any idea why or what the correct syntax need to look like?
cheers
I have tested your card configuration on my instance with both sensor
and binary_sensor
entities created using the Template Helper, and both are working for me.
Just to double-check, have you tried it with multiple or infinite spins to make sure you’re not just missing it?
Also, your template is a bit strange… the elif
really isn’t doing anything that wouldn’t be covered better just using an else
.
hey man
this is wired. i guess im doing something wrong (well… obviously…). just not sure what, yet.
i thought maybe the card does not work with helpers, but now that you have proved it does, ill just keep testing.
can you please write down the entire “template” with “else” instead of “elif” - for as to just changing the two does not work for me (not surprisingly…
)
for now, as a “work around”, i created a sensor in the yaml config with this code:
- platform: template
sensors:
running_water_indicator:
friendly_name: "running water indicator"
icon_template: mdi:water-pump
value_template: "{% if states('sensor.water_flow_meter') | float > 0%} on {% elif states('sensor.water_flow_meter') | float < 0.01%} off {% endif %}"
and for some reason, this one works fine with the custom button card and animations
There are many ways to write it, in the standard form it would be:
...
value_template: |
{% if states('sensor.water_flow_meter')|float(0) > 0%} on
{% else %} off {% endif %}
I would probably use iif()
since this is not a complicated if/then:
...
value_template: |
{{ iif( states('sensor.water_flow_meter')|float(0) > 0, 'on', 'off') }}
Or, since you expect an on/off output, use a binary sensor…
binary_sensor:
- platform: template
sensors:
running_water_indicator:
friendly_name: "running water indicator"
icon_template: mdi:water-pump
value_template: "{{ states('sensor.water_flow_meter')|float(0) > 0 }}"
thanks man
i marked your last answer as “solution”. as it is that… ![:slight_smile: :slight_smile:](https://community.home-assistant.io/images/emoji/twitter/slight_smile.png?v=10)
thanks and cheers