rianadon/timer-bar-card

Script for 15mins and 30mins on sprinkler which always turns off after 10mins

Opened this issue · 1 comments

So, I have a sprinkler system that always turns off after 10mins

I created 2 buttons that will turn the sprinklers on for both 15 and 30mins

15mins button code :

type: custom:timer-bar-card
icon: mdi:sprinkler-variant
entity: switch.woox_irrigation_valve_switch
name: Sprinklers on for 15mins
mushroom:
  layout: vertical
  color: green
duration:
  script: script.irrigation_on_15mins
tap_action:
  action: call-service
  service: script.irrigation_on_15mins
hold_action:
  action: more-info

script.irrigation_on_15mins code :

alias: Sprinklers on for 15mins
sequence:
  - if:
      - condition: state
        entity_id: switch.woox_irrigation_valve_switch
        state: "on"
    then:
      - data: {}
        target:
          entity_id: switch.woox_irrigation_valve_switch
        action: homeassistant.turn_off
      - stop: ""
  - data: {}
    target:
      entity_id: switch.woox_irrigation_valve_switch
    action: homeassistant.turn_on
  - delay:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0
  - data: {}
    target:
      entity_id: switch.woox_irrigation_valve_switch
    action: homeassistant.turn_on
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - data: {}
    target:
      entity_id: switch.woox_irrigation_valve_switch
    action: homeassistant.turn_off
  - data:
      message: Sprinkler 15mins finished
    action: notify.mobile_app_samsung_gsm_genara
  - data:
      message: Sprinkler 15mins finished
    action: notify.mobile_app_galaxy_s23_miguel
mode: restart
description: Turn on Sprinklers for 15mins
icon: mdi:water-pump

30mins button code

type: custom:timer-bar-card
icon: mdi:sprinkler-variant
entity: switch.woox_irrigation_valve_switch
name: Sprinklers on for 30mins
mushroom:
  layout: vertical
  color: green
duration:
  script: script.irrigation_on_30mins
tap_action:
  action: call-service
  service: script.irrigation_on_30mins
hold_action:
  action: more-info

script.irrigation_on_30mins code :

alias: Sprinklers on for 30mins
sequence:
  - if:
      - condition: state
        entity_id: switch.woox_irrigation_valve_switch
        state: "on"
    then:
      - data: {}
        target:
          entity_id: switch.woox_irrigation_valve_switch
        action: homeassistant.turn_off
      - stop: ""
  - data: {}
    target:
      entity_id: switch.woox_irrigation_valve_switch
    action: homeassistant.turn_on
  - delay:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0
  - data: {}
    target:
      entity_id: switch.woox_irrigation_valve_switch
    action: homeassistant.turn_on
  - delay:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0
  - data: {}
    target:
      entity_id: switch.woox_irrigation_valve_switch
    action: homeassistant.turn_on
  - delay:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0
  - data: {}
    target:
      entity_id: switch.woox_irrigation_valve_switch
    action: homeassistant.turn_off
  - data:
      message: Sprinkler 30mins finished
    action: notify.mobile_app_samsung_gsm_genara
  - data:
      message: Sprinkler 30mins finished
    action: notify.mobile_app_galaxy_s23_miguel
mode: restart
description: Turn on Sprinklers for 30mins
icon: mdi:water-pump

The problem is that the timer only takes the first "delay" instance into account and shows a 10min countdown for both buttons.

Using duration fixed : 00:15:00 and fixed : 00:30:00 does not work, because then both buttons start to countdown even when I only clicked on 1

What solution can you provide, please ?

That's quite the complex script you have :D The card doesn't have very much insight into the entire script; it only is able to see the last action taken by examining the attributes of the script entity. So you're right, it's only going to use the time in the first delay instance.

I don't think there's any other way around this besides further complicating your setup and adding two timer entities. I would create a "Sprinkler status 15m" timer and "Sprinkler status 30m" timer. At the beginning of your script, you would start the timer, and assuming all goes well the timer should stop by the time the script finishes.

Then, you can configure the card with the timer. To keep more-info pointing to the correct entity, you can use the more_info service in the browser mod addon.