I looked at the scripts document more closely and realized my mistake. I needed to use “data_template:” instead of “data:” in the YAML when supplying the channel number in the script. So this works:
Marius, thanks for Name solution! Worked fine.
Petro, could you please be more specific - I am tooo nubie for templates…
How can I switch betwwen 2 background colors? where should i place " < number" ?
in regards to the value? It wouldn’t be a template, it would be a style based on state. Don’t use template, just use operator as greater than or less than. If you use a template, you need to convert the state to a number.
Petro is right, you’re using incorrect operators and templates are not required to get what you want.
still, templates can come in quite handy and make the button config much shorter:
styles:
card:
- background-color: >
[[[ var state = entity.state;
if (state > 20) return '#bf4040';
if (state > 8) return '#c78822';
return '#819662'; ]]]
as you noticed I made the template work out the else for itself, being below or equal to 8.
In your setup you wouldnt have a value between 7 and 8… unless you’d define a default value, which, again, is totally possible, and explained in the docs.
Love the versatility of this card. So of course I’ve come up with a use-case that requires yet another option
Here’s my current situation:
I’ve got a 4-relay ESP device, flashed with Tasmota and connected back to home assistant via mqtt. The relays are attached to motors of an adjustable bed: Head Up, Head Down, Foot Up, Foot Down. The original wired remote just required you to hold down a button for as long as you wanted to raise or lower the head or foot of the bed, and (thankfully) there was built-in circuitry to stop the motors from running when reaching the highest or lowest positions.
Everything is working great to just send an mqtt on or off (or toggle) command via a tap_action, but I wanted to replicate the experience of the original remote as closely as possible: holding a button down until the bed reaches a position I desire. Tasmota has a PulseTime option, and that seemed promising in combination with button-card’s hold_action and repeat: Pulsetime in tasmota will switch the relay off after a programmed duration, unless an On command is received before the duration expires. So if I set the pulsetime to 250ms and repeat a switch.turn_on command every 100ms, the motor continues running until the last On command is received (+250ms).
While not ideal, a 250ms lag before shutting off would be acceptable, except what actually happens quite frequently(but not always) is that it gets confused and some late On commands arrive after I let go of the button. This causes the bed to continue rising or lowering in a jerky fashion until the last command gets through…definitely not the experience I was going for and even more importantly simply unacceptable to my wife . I’m assuming it’s down to wireless and tcp latency issues that are simply out of my control, my network is not overly complicated and I don’t have any other issues with it that I can ascribe this problem to. Or possibly Tasmota or mosquitto can’t keep up with the commands coming through that fast.
What would be ideal, is that instead of using repeat, if hold_action also (or alternatively) supported a release_action that would follow the same format as the other action commands (allowing for call-service, etc.). That would allow me to do away with pulsetime in tasmota, be less spammy on the network (just an ON command when hold is initiated, and an OFF when it is released), and should be more accurate about stopping the motors at the precise time (+/- a couple ms) you release the hold of the button.
I see this being useful for other projects as well, for instance to open or close curtains to an arbitrary position using the same principals.
I was wondering if I could drop in and get some advice around something I’ve been trying to setup. I want to create a button card, of an image (Xiaomi Temp Sensor) mainly filling if not centered with the battery level info (binary sensor) in the top right. My attempts so far have taken several hours and many head bangs …
I’m sure this was discussed a while ago but this thread is already so long I have to ask again…
Every time I press the Button in the new iOS app it presses “double”.
It turns on and directly off.