Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
migueldc73 opened this issue Aug 14, 2024 · 1 comment

Comments

@migueldc73
Copy link

migueldc73 commented Aug 14, 2024

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 ?

@rianadon
Copy link
Owner

rianadon commented Sep 9, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants