Hello,
I built a slider for the time and buttons to start watering different areas of the yard.
The slider sets the time and then I would like to start watering a selected area.
I am using two custom cards for this, but when I press the button it always starts the watering for the default time of 5 minutes.
So the service/data/minutes is ignored for some reason.
The input_number is set up in helpers and it works fine in dev tools/services using this:
service: bhyve.start_watering
data:
entity_id: switch.sprinklers_zone
minutes: "{{ states('input_number.sprinkler_time') | int }}"
I tried:
- input_number.sprinkler_time
- “{{ states(‘input_number.sprinkler_time’) | int }}”
but neither option works on the button code below:
type: vertical-stack
cards:
- type: custom:slider-button-card
entity: input_number.sprinkler_time
name: Time
compact: true
icon:
icon: mdi:water-outline
slider:
direction: left-right
background: gradient
show_track: true
action_button:
show: false
- type: horizontal-stack
cards:
- type: custom:button-card
name: Sprinklers
entity: switch.sprinklers_zone
styles:
card:
- height: 80px
state:
- value: 'off'
icon: mdi:water-check
tap-action:
action: call-service
service: bhyve.start_watering
data:
entity_id: switch.sprinklers_zone
minutes: input_number.sprinkler_time
- value: 'on'
icon: mdi:water-outline
tap-action:
action: call-service
service: bhyve.stop_watering
data:
entity_id: switch.sprinklers_zone
Any ideas? Thank you very much in advance for your help!
i think the custom:button-card in the front end does javascript and not jinja.
personally what i would do is have them call scripts of yours and have your scripts to the work and reference the helpers.
OK, I made a separate script like this:
alias: startsprinkler
sequence:
- service: bhyve.start_watering
data:
entity_id: switch.sprinklers_zone
minutes: 2
mode: single
The script works if I start it from dev tools and even from a completely new standard button that starts the script.
But if I start it from the custom button card, the exact same script defaults to 5 minutes. Even if I hard-code the 2 minutes in there like above!? This just doesn’t make any sense to me.
I changed it to this:
type: custom:button-card
name: Sprinklers
entity: switch.sprinklers_zone
styles:
card:
- height: 80px
state:
- value: 'off'
icon: mdi:water-check
tap-action:
action: call-service
service: script.startsprinkler
- value: 'on'
icon: mdi:water-outline
tap-action:
action: call-service
service: bhyve.stop_watering
data:
entity_id: switch.sprinklers_zone
that is indeed bizarre…
using the new button card, invoke it. then verify the script was triggered. then post the trace of the script. let’s see it make the call.
OK, so I found out one thing: the button starts the sprinklers just because of the entity in the 3rd line of the code. Everything underneath doesn’t do anything (other than make the button look pretty). It doesn’t execute the script at all, which explains why it defaults to the 5 minute time.
[Edit] This does exactly what my original code does:
type: custom:button-card
name: Sprinklers
entity: switch.sprinklers_zone
styles:
card:
- height: 80px
state:
- value: 'off'
icon: mdi:water-check
- value: 'on'
icon: mdi:water-outline
Now I need to figure out how to configure that correctly (I am fairly new to Home Assistant and find it very confusing)
Not sure if I can send the minutes with the entity or however that works.
try this and tell me how it does.
type: custom:button-card
name: Sprinklers
entity: switch.sprinklers_zone
styles:
card:
- height: 80px
tap_action:
action: call-service
service: script.startsprinkler
state:
- value: 'off'
icon: mdi:water-check
- value: 'on'
icon: mdi:water-outline
1 Like
Yep, that works. Seems like the tap-action cannot be nested in a state, I guess.
Well, at least the changed button icon works a lot better with the custom button. I wasn’t able to get that working with the normal default button.
cool. so you need to turn your script into a toggle. to get your original behavior objective. i presume you know how to do that. holler if you need help. otherwise you’re all set?
Yes, I got it to work already. Thanks for your help!!
Just for completeness, here are the final scripts and how it looks:
type: custom:slider-button-card
entity: input_number.watering_time
name: Time
compact: true
icon:
icon: mdi:water-outline
slider:
direction: left-right
background: gradient
show_track: true
action_button:
show: false
type: custom:button-card
name: Sprinklers
entity: switch.sprinklers_zone
styles:
card:
- height: 80px
tap_action:
action: call-service
service: script.start_watering_sprinklers
state:
- value: 'off'
icon: mdi:water-check
- value: 'on'
icon: mdi:water-outline
alias: Start watering Sprinkler
sequence:
- if:
- condition: state
entity_id: switch.sprinklers_zone
state: "off"
then:
- service: bhyve.start_watering
data:
entity_id: switch.sprinklers_zone
minutes: "{{ states('input_number.watering_time') | int }}"
else:
- service: bhyve.stop_watering
data:
entity_id: switch.sprinklers_zone
mode: single
icon: mdi:water