rgc99 / irrigation_unlimited

♒Irrigation controller for Home Assistant
MIT License
329 stars 49 forks source link

irrigation_unlimited_start does not fire the automation #134

Open Kolia56 opened 1 year ago

Kolia56 commented 1 year ago

I'm just trying to get the following example from the documentation working without success so far. I have only tested Manual run (no event is fired). I haven't tested automatic start, time will tell. Am I misunderstanding something?

Configuration ``` irrigation_unlimited: controllers: - name: "Controleur 1" all_zones_config: show: timeline: true allow_manual: true # duration: "0:10:00" zones: - name: Café François zone_id: "1" entity_id: switch.vanne_atelier_gui maximum: "00:45:00" # schedules: # - time: "22:00" # name: "1" # duration: "00:20" - name: Serre zone_id: "2" entity_id: switch.vanne_maison_journalier_gui maximum: "00:30:00" # schedules: # - time: "23:00" # name: "2" # duration: "00:20" - name: Pelouse zone_id: "3" entity_id : switch.vanne_jardin_devant_gui maximum: "01:10:00" - name: Deux carrés zone_id: "4" entity_id: switch.vanne_deux_carres_gui maximum: "00:45:00" - name: Un carré zone_id: "5" entity_id: switch.vanne_un_carre_gui maximum: "00:30:00" - name: Petits fruits zone_id: "6" entity_id: switch.vanne_petits_fruits_gui maximum: "00:50:00" - name: Haie - Céanothe - Fleurs zone_id: "7" entity_id: switch.vanne_haie_gui maximum: "01:00:00" - name: Pommiers zone_id: "8" entity_id: switch.vanne_pommiers_gui maximum: "00:30:00" - name: Pare-terre Julie zone_id: "9" entity_id: switch.vanne_buanderie_grande_maison_gui maximum: "00:45:00" - name : Haies pelouses zone_id: "10" entity_id: switch.718 maximum: "00:45:00" - name: If Cour carrée entity_id: switch.vanne_salle_claudine_gui zone_id: "11" maximum: "00:20:00" - name: Haie du fond zone_id: "12" entity_id: switch.vanne_haie_fond_gui maximum: "01:40:00" - name: Tilleul zone_id: "13" entity_id: switch.vanne_tilleul_gui maximum: "00:40:00" sequences: - name: nuit # delay: "-00:00:02" schedules: - name: 1 time: "22:00" schedule_id: "s1" zones: - zone_id: 1 # Café François duration: "00:30" - zone_id: 2 # Serre et autres duration: "00:20" - zone_id: 9 # Pare-terre Julie duration: "00:30" - zone_id: 4 # Deux carrés duration: "00:30" - zone_id: 5 # Un carré duration: "00:20" - zone_id: 6 # Petits fruits duration: "00:30" - zone_id: 7 # Haie - Céanothe duration: "00:40" - zone_id: 8 # Pommiers duration: "00:20" - zone_id: 10 # Haies pelouse duration: "00:25" - zone_id: 11 # If cour carrée duration: "00:10" - zone_id: 12 # Haie du fond duration: "00:30" - zone_id: 13 # Tilleul - Cerisier duration: "00:30" - zone_id: 3 # Pelouse duration: "00:40" - name: jour duration: "00:05" delay: "02:25" repeat: 3 schedules: - name: 2 time: "12:00" schedule_id: "s2" zones: - zone_id: 2 - name: "Controleur 2" all_zones_config: show: timeline: true allow_manual: true zones: - name: Aérateur bac zone_id: "1" entity_id: switch.aerateur_bac sequences: - name: Bac schedules: - name: "bac" time: "00:15" schedule_id: "bac" zones: - zone_id: 1 # bac duration: "00:50" delay: "01:40" repeat: 6 ```

Automation

 id: a43d818a-787e-41ba-b5d3-f5129599168e
    alias: "Irrigation Unlimited starting"
    trigger:
      platform: event
      event_type: irrigation_unlimited_start
    action:
      - service: notify.persistent_notification
        data:
          title: "Irrigation Unlimited - Starting"
          message: |
            Time: {{ as_local(trigger.event.time_fired).strftime('%c') }}
            Controller: {{ trigger.event.data.controller.index + 1 }} {{ trigger.event.data.controller.name }}
            Sequence: {{ trigger.event.data.sequence.index + 1 }} {{ trigger.event.data.sequence.name }}
            Schedule: {% if trigger.event.data.schedule.index is integer %}{{ trigger.event.data.schedule.index + 1 }} {{ trigger.event.data.schedule.name }}{% else %}Manual{% endif %}
            Duration: {{ timedelta(seconds=trigger.event.data.run.duration) }}

Version of the custom_component: very latest version, downloaded from repositery

Logs (excerpt) ``` 2023-08-13 12:00:00.021 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 12:00:00] controller: 1, zone: 0, state: 1 2023-08-13 12:00:00.022 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 12:00:00] controller: 1, zone: 2, state: 1, data: 2.1.2.1.1 2023-08-13 12:05:00.020 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 12:05:00] controller: 1, zone: 2, state: 0 2023-08-13 12:05:00.020 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 12:05:00] controller: 1, zone: 0, state: 0 2023-08-13 12:45:00.021 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 12:45:00] controller: 2, zone: 0, state: 1 2023-08-13 12:45:00.022 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 12:45:00] controller: 2, zone: 1, state: 1, data: 1.1.1.1.1 2023-08-13 13:35:00.029 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 13:35:00] controller: 2, zone: 1, state: 0 2023-08-13 13:35:00.030 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 13:35:00] controller: 2, zone: 0, state: 0 2023-08-13 14:30:00.033 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 14:30:00] controller: 1, zone: 0, state: 1 2023-08-13 14:30:00.033 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 14:30:00] controller: 1, zone: 2, state: 1, data: 2.1.2.1.1 2023-08-13 14:35:00.022 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 14:35:00] controller: 1, zone: 2, state: 0 2023-08-13 14:35:00.022 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 14:35:00] controller: 1, zone: 0, state: 0 2023-08-13 14:44:31.045 DEBUG (MainThread) [custom_components.irrigation_unlimited] LOAD 2023-08-13 14:44:31.065 DEBUG (MainThread) [custom_components.irrigation_unlimited] STOP 2023-08-13 14:44:31.065 DEBUG (MainThread) [custom_components.irrigation_unlimited] START 2023-08-13 14:45:39.285 DEBUG (MainThread) [custom_components.irrigation_unlimited] LOAD 2023-08-13 14:45:39.305 DEBUG (MainThread) [custom_components.irrigation_unlimited] STOP 2023-08-13 14:45:39.305 DEBUG (MainThread) [custom_components.irrigation_unlimited] START 2023-08-13 17:00:00.025 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 17:00:00] controller: 1, zone: 0, state: 1 2023-08-13 17:00:00.025 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 17:00:00] controller: 1, zone: 2, state: 1, data: 2.1.2.1.1 2023-08-13 17:05:00.025 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 17:05:00] controller: 1, zone: 2, state: 0 2023-08-13 17:05:00.025 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 17:05:00] controller: 1, zone: 0, state: 0 2023-08-13 19:49:41.490 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new automation.automation entity: automation.irrigation_unlimited_starting 2023-08-13 19:49:41.499 INFO (MainThread) [homeassistant.components.automation.irrigation_unlimited_starting] Initialized trigger Irrigation Unlimited starting 2023-08-13 19:50:13.192 INFO (MainThread) [custom_components.irrigation_unlimited] CALL [2023-08-13 19:50:13] service: manual_run, controller: 1, zone: 2, data: {"entity_id": ["binary_sensor.irrigation_unlimited_c1_z2"], "time": "0:02:00"} 2023-08-13 19:50:14.015 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 19:50:14] controller: 1, zone: 0, state: 1 2023-08-13 19:50:14.015 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 19:50:14] controller: 1, zone: 2, state: 1, data: 2.0.0.0.0 2023-08-13 19:50:36.888 INFO (MainThread) [custom_components.irrigation_unlimited] CALL [2023-08-13 19:50:36] service: cancel, controller: 1, zone: 2, data: {"entity_id": ["binary_sensor.irrigation_unlimited_c1_z2"]} 2023-08-13 19:50:36.894 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 19:50:14] controller: 1, zone: 2, state: 0 2023-08-13 19:50:36.895 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 19:50:14] controller: 1, zone: 0, state: 0 2023-08-13 19:51:40.407 INFO (MainThread) [custom_components.irrigation_unlimited] CALL [2023-08-13 19:51:40] service: manual_run, controller: 1, zone: 2, data: {"entity_id": ["binary_sensor.irrigation_unlimited_c1_z2"], "time": "0:02:00"} 2023-08-13 19:51:41.010 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 19:51:41] controller: 1, zone: 0, state: 1 2023-08-13 19:51:41.010 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 19:51:41] controller: 1, zone: 2, state: 1, data: 2.0.0.0.0 2023-08-13 19:52:17.272 INFO (MainThread) [custom_components.irrigation_unlimited] CALL [2023-08-13 19:52:17] service: cancel, controller: 1, zone: 2, data: {"entity_id": ["binary_sensor.irrigation_unlimited_c1_z2"]} 2023-08-13 19:52:17.279 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 19:52:12] controller: 1, zone: 2, state: 0 2023-08-13 19:52:17.279 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 19:52:12] controller: 1, zone: 0, state: 0 2023-08-13 19:54:17.375 INFO (MainThread) [custom_components.irrigation_unlimited] CALL [2023-08-13 19:54:17] service: manual_run, controller: 1, zone: 2, data: {"entity_id": ["binary_sensor.irrigation_unlimited_c1_z2"], "time": "0:02:00"} 2023-08-13 19:54:18.007 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 19:54:18] controller: 1, zone: 0, state: 1 2023-08-13 19:54:18.007 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 19:54:18] controller: 1, zone: 2, state: 1, data: 2.0.0.0.0 2023-08-13 19:56:03.409 INFO (MainThread) [homeassistant.components.automation.irrigation_unlimited_starting] Initialized trigger Irrigation Unlimited starting 2023-08-13 19:56:08.256 DEBUG (MainThread) [custom_components.irrigation_unlimited] LOAD 2023-08-13 19:56:08.272 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 19:56:08] controller: 1, zone: 2, state: 0 2023-08-13 19:56:08.273 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 19:56:08] controller: 1, zone: 0, state: 0 2023-08-13 19:56:08.274 DEBUG (MainThread) [custom_components.irrigation_unlimited] STOP 2023-08-13 19:56:08.275 DEBUG (MainThread) [custom_components.irrigation_unlimited] START 2023-08-13 19:56:32.461 INFO (MainThread) [custom_components.irrigation_unlimited] CALL [2023-08-13 19:56:32] service: manual_run, controller: 1, zone: 2, data: {"entity_id": ["binary_sensor.irrigation_unlimited_c1_z2"], "time": "0:02:00"} 2023-08-13 19:56:33.005 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 19:56:33] controller: 1, zone: 0, state: 1 2023-08-13 19:56:33.006 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 19:56:33] controller: 1, zone: 2, state: 1, data: 2.0.0.0.0 2023-08-13 19:57:19.172 INFO (MainThread) [custom_components.irrigation_unlimited] CALL [2023-08-13 19:57:19] service: cancel, controller: 1, zone: 2, data: {"entity_id": ["binary_sensor.irrigation_unlimited_c1_z2"]} 2023-08-13 19:57:19.180 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 19:57:06] controller: 1, zone: 2, state: 0 2023-08-13 19:57:19.180 INFO (MainThread) [custom_components.irrigation_unlimited] EVENT [2023-08-13 19:57:06] controller: 1, zone: 0, state: 0 2023-08-13 20:06:03.264 INFO (MainThread) [custom_components.irrigation_unlimited] CALL [2023-08-13 20:06:03] service: manual_run, controller: 1, zone: 2, data: {"entity_id": ["binary_sensor.irrigation_unlimited_c1_z2"], "time": "0:00:00"} ```
Kolia56 commented 1 year ago

I got the picture. I overlooked this "These events are fired when a sequence starts and finishes." I just go it fired when a watering sequence started. I guess I've been fooled by the name of the event, that maybe should be better named: irrigation_unlimited_sequence_start? Which means I guess that when not using sequences scheme no event is fired. Am I correct? Then question arises: would it be of interest to have such event fired when a zone schedule starts or finishes?

rgc99 commented 1 year ago

Correct, you only get these messages when using sequences. You can use the state platform to get a zone or controller on/off. It might be handy to fire one on the zone as well. Let me know if you can't do what you need using the state platform.

automation:
 id: a43d818a-787e-41ba-b5d3-f5129599168e
    alias: "Irrigation Unlimited starting"
    trigger:
      - platform: state
        entity_id:
          binary_sensor.irrigation_unlimited_c1_z1
        from: "off"
        to: "on"
    action:
...
Kolia56 commented 1 year ago

Thank you. As a matter of fact I'm pairing HA smart irrigation (HASI) to Irrigation unlimited. I installed it 2 months ago or so and until now I was just watching the results (I have a Davis VP2 providing ET calculation). I'm pretty impressed by the relevance of them. I just have to add some logic related to rain forecast. HASI is currently set-up to calculate the watering time 10' before the watering sequence starts. I'd like to make it more dynamic in case I decide to change start-up time. In other words, when the sequence starts and it is not "manual" which is kind of unlikely to happen, so the first sprinkler is already on, I'd like to trigger HASI computation thanks to "smart_irrigation.calculate_daily_adjusted_run_time" service and set the percentage at controller level. I'm under the impression that if the percentage is applied at the controller level after watering started, new duration will be applied to the next run not the current one. Am I correct?

rgc99 commented 1 year ago

Correct, changing the adjustment will not effect any running schedules.

Kolia56 commented 1 year ago

I ended up with this automation which fair enough. If watering start time is changed, its is fairly easy to update the code. I still have to add some logic related to rain forecast and soil moisture. I works very well so far.

It would be nice to be able to template schedule start time, then everything could be based on that. Any thoughts?

  - id: c6b40384-a7bd-4cf9-82f8-fc07f15905e5
    alias: Smart Irrigation adjustment
    description: Adjust watering times based on smart irrigation calculations
    trigger:
      - platform: time
        at: "21:58:05"
        id: compute_watering_duration
      - platform: time
        at: "21:59:06"
        id: set_watering_duration
    condition:
      condition: and
      conditions:
        - "{{ states('sensor.smart_irrigation_id7_daily_adjusted_run_time') | float(-1) >= 0 }}"
    action:
      - choose:
        - conditions:
          - condition: trigger
            id: compute_watering_duration
          sequence:
          - service: smart_irrigation.smart_irrigation_id7_calculate_daily_adjusted_run_time
            data: {}
        - conditions:
          - condition: trigger
            id: set_watering_duration
          sequence:
          - service: input_text.set_value
            target: 
              entity_id: input_text.smart_irrigation_id7_adjust_time
            data: # 2600 secondes = 00:40:00 nominal duration for lawn watering
            # all other circuits (drip line) are proportional to lawn watering
              value: >
                {{ timedelta(seconds=states('sensor.smart_irrigation_id7_daily_adjusted_run_time') | int(0)) }} - 
                {{(states('sensor.smart_irrigation_id7_daily_adjusted_run_time')| int(0) / 2600) | multiply (100) | round (0) }}%
          - condition: state
            entity_id: input_boolean.irrigation_duration_smart
            state: "on"
          - service: irrigation_unlimited.adjust_time
            data: 
              entity_id: binary_sensor.irrigation_unlimited_c1_m
              percentage: >
                {% set value = (states('sensor.smart_irrigation_id7_daily_adjusted_run_time')| int(0) / 2600) | multiply (100) | round (0) %}
                {% if value >= 200 %} then
                  200
                {% else %}
                  {{value}}
                {% endif %}
    mode: single
rgc99 commented 1 year ago

Not sure what you want to do exactly with the start time. Could you expand your thoughts.

Kolia56 commented 1 year ago

Yes with pleasure. If sequence start time is set by an input_datetime helper, the automation triggers above could referred to it minus 1 minute and minus 2 minutes for instance. Triggers would be then dynamic instead of being static.

rgc99 commented 1 year ago

Can you use the load_schedule service call to alter the schedule? Automations have built in templating.

Kolia56 commented 1 year ago

Thank you, I see, if start time is needed to be changed then I do it by load_schedule (instead of doing it in the .yaml) and then I can use the same reference minus some time to change time at which events are fired.

Kolia56 commented 1 year ago

So I had to defined two template sensors:

template: 
  - sensor:
    - name: hasmart_irrigation_time_trigger
      state: >
        {{ ((state_attr('input_datetime.watering_s1_start', 'timestamp') - 50)  | timestamp_custom(local=False))[-8:] }}
    - name: irrigation_unlimited_watering_computation_trigger
      state: >
        {{ ((state_attr('input_datetime.watering_s1_start', 'timestamp') - 40)  | timestamp_custom(local=False))[-8:] }}

And then final code for automation:

  - id: c6b40384-a7bd-4cf9-82f8-fc07f15905e5
    alias: Smart Irrigation adjustment
    description: Adjust watering times based on smart irrigation calculations
    trigger:
      - platform: time
        at: sensor.hasmart_irrigation_time_trigger
        id: watering_duration_compute
      - platform: time
        at: sensor.irrigation_unlimited_watering_computation_trigger
        id: watering_duration_set
    condition:
      condition: and
      conditions:
        - "{{ states('sensor.smart_irrigation_id7_daily_adjusted_run_time') | float(-1) >= 0 }}"
    action:
      - choose:
        - conditions:
          - condition: trigger
            id: watering_duration_compute
          sequence:
          - service: smart_irrigation.smart_irrigation_id7_calculate_daily_adjusted_run_time
            data: {}
        - conditions:
          - condition: trigger
            id: watering_duration_set
          sequence:
          - service: input_text.set_value
            target: 
              entity_id: input_text.smart_irrigation_id7_adjust_time
            data: # 2600 secondes = 00:40:00 nominal duration for lawn watering
            # all other circuits (drip line) are proportional to lawn watering
              value: >
                {{ timedelta(seconds=states('sensor.smart_irrigation_id7_daily_adjusted_run_time') | int(0)) }} - 
                {{(states('sensor.smart_irrigation_id7_daily_adjusted_run_time')| int(0) / 2600) | multiply (100) | round (0) }}%
          - condition: state
            entity_id: input_boolean.irrigation_duration_smart
            state: "on"
          - service: irrigation_unlimited.adjust_time
            data: 
              entity_id: binary_sensor.irrigation_unlimited_c1_m
              percentage: >
                {% set value = (states('sensor.smart_irrigation_id7_daily_adjusted_run_time')| int(0) / 2600) | multiply (100) | round (0) %}
                {% if value >= 200 %} then
                  200
                {% else %}
                  {{value}}
                {% endif %}
    mode: single

and the snippet for load_schedule

  - id: 1962673f-0796-4a3c-8f01-d0a9cfa78213
    alias: irrigation unlimited - Schedule s1, update start time
    trigger:
      - platform: state
        entity_id: 
          - input_datetime.watering_s1_start
    action:
      service: irrigation_unlimited.load_schedule
      data:
        schedule_id: s1
        time: "{{states('input_datetime.watering_s1_start')}}"

So no matter the sequence start time, I'm now sure that watering time will be computed just a bit before the sequence starts.

rgc99 commented 1 year ago

Please note that currently changes made to schedules with the load_schedule are not saved. They will revert to the configuration.yaml after a HA restart. You might want to add a HA start event trigger.

    trigger:
      - platform: homeassistant
        event: start
Kolia56 commented 1 year ago

thank you for the tip. I'll make sure a piece of code is added at startup.

rgc99 commented 1 year ago

I think you can combine into your automation like this.

    trigger:
      - platform: state
        entity_id: 
          - input_datetime.watering_s1_start
      - platform: homeassistant
        event: start
Kolia56 commented 1 year ago

You are right, thank you. I'll will shortly update the code above. I discovered that trying to make a template sensor from an input_datetime is a dead end because it is not viewed as datetime object. As a consequence, events are not fired.

rgc99 commented 1 year ago

Perhaps these articles might help; https://community.home-assistant.io/t/trigger-an-automation-before-the-time-of-a-time-helper/236667 https://community.home-assistant.io/t/automation-trigger-15-min-before-specified-time/304827

Kolia56 commented 1 year ago

Thanks for the tip, I never experienced yet the template trigger, I think it can make it. HA is full of ressources

Kolia56 commented 1 year ago

Here is the final code, no templates. Much more elegant and efficient. Watering time is computed 2 minutes before scheduled time and set one minute before it. Again thank you very much for your kind help.

  - id: c6b40384-a7bd-4cf9-82f8-fc07f15905e5
    alias: Smart Irrigation adjustment
    description: Adjust watering times based on smart irrigation calculations
    trigger:
      - platform: template
        value_template: >
          {{ now().timestamp() | timestamp_custom('%H:%M') 
            == (state_attr('input_datetime.watering_s1_start', 'timestamp') - 120) | timestamp_custom('%H:%M', false) }}
        id: watering_duration_compute
      - platform: template
        value_template: >
          {{ now().timestamp() | timestamp_custom('%H:%M') 
            == (state_attr('input_datetime.watering_s1_start', 'timestamp') - 60) | timestamp_custom('%H:%M', false) }}
        id: watering_duration_set
    condition:
      condition: and
      conditions:
        - "{{ states('sensor.smart_irrigation_id7_daily_adjusted_run_time') | float(-1) >= 0 }}"
    action:
      - choose:
        - conditions:
          - condition: trigger
            id: watering_duration_compute
          sequence:
          - service: smart_irrigation.smart_irrigation_id7_calculate_daily_adjusted_run_time
            data: {}
          - service: notify.persistent_notification
            data:
              title: "HA smart irrigation - calcul du temps d'arrosage"
              message: |
                Time: {{ as_local(now()).strftime('%c') }}            
        - conditions:
          - condition: trigger
            id: watering_duration_set
          sequence:
          - service: input_text.set_value
            target: 
              entity_id: input_text.smart_irrigation_id7_adjust_time
            data: # 2600 secondes = 00:40:00 nominal duration for lawn watering
            # all other circuits (drip lines) are proportional to lawn watering
              value: >
                {{ timedelta(seconds=states('sensor.smart_irrigation_id7_daily_adjusted_run_time') | int(0)) }} - 
                {{(states('sensor.smart_irrigation_id7_daily_adjusted_run_time')| int(0) / 2600) | multiply (100) | round (0) }}%
          - service: notify.persistent_notification
            data:
              title: "Irrigation - application du nouveau temps d'arrosage"
              message: |
                Time: {{ as_local(now()).strftime('%c') }}            
          - condition: state
            entity_id: input_boolean.irrigation_duration_smart
            state: "on"
          - service: input_number.set_value
            target:
              entity_id: input_number.arrosage_variation
            data:
              value: >
                {% set pct = (states('sensor.smart_irrigation_id7_daily_adjusted_run_time')| int(0) / 2600) | multiply (100) | round (0) %}
                {% if pct >= 150 %} then
                  150
                {% else %}
                  {{pct}}
                {% endif %}
    mode: single

And this is the piece of code that sets the watering time using percentage at controller level:

  - id: ad1617dd-c0ae-40d4-8421-08ae31f84cb5
    alias: Irrigation - Modification paramètres d'arrosage
    description: ''
    trigger:
    - platform: state
      entity_id:
      - input_button.arrosage_reset
      id: reset
    - platform: state
      entity_id:
        - input_number.arrosage_variation    
      id: pct
    condition: []
    action:
      - choose:
        - conditions:
          - condition: trigger
            id: reset
          sequence:
            - service: input_number.set_value
              target:
                entity_id: input_number.arrosage_variation
              data:
                value: '100'
        - conditions:
          - condition: trigger
            id: pct
          sequence:
            - if:
                - condition: template
                  value_template: >
                    {{states("input_number.arrosage_variation") != "100.0" }}
              then:
                - service: irrigation_unlimited.adjust_time
                  data:
                    entity_id: binary_sensor.irrigation_unlimited_c1_m
                    percentage: >
                      {{ states("input_number.arrosage_variation")}}
              else:
                - service: irrigation_unlimited.adjust_time
                  data:
                    entity_id: binary_sensor.irrigation_unlimited_c1_m
                    reset:         
    max: 5
    mode: queued