Days selector for automation run

Hi, I would need to create a selector to decide every how many days to run an automation (e.g. every 2 days, every 6 days, etc.), editable with a slider on the lovelace.
Is there any way to create it? Can you advise me? Thanks

Ok but I can’t put it into automation like I would like.
Can you give me an example of an automation that runs every 3 days?

You haven’t told us how you would like to use it in your automation… “Runs every 3 days” is a vague requirement. You need to clarify exactly how you want your automation to work… For example, should it run every x days at a certain time of day? Or, should it run x days after a certain event occurs? If you aren’t specific with your question, it is difficult for us to be specific with an answer.

How to Ask a Good Question

The following automation turns on a switch at 09:00 every X days, where X is the value of input_number.your_interval, and then turns off the switch at 18:00.

alias: Example
trigger:
  - platform: time
    at:
      - '09:00:00'
      - '18:00:00'
condition: "{{ (now() - as_datetime(0)).days % states('input_number.your_interval') | int(1) == 0 }}"
action:
  - service: "switch.turn_{{ iif(now().hour == 9, 'on', 'off') }}"
    target:
      entity_id: switch.your_switch

Like Didgeridrew explained, we don’t know what you want the automation to do other than “run every X days” so the example I provided may require changes to meet your detailed requirements.

I’m sorry, I thought I explained well.
Basically I would like to add to this automation the possibility of deciding every how many days it is performed, for example every 2 days, managed by a slider.

automation: 
- alias: Irrigazione Vasi
  initial_state: true
  trigger:
    platform: template
    value_template: >-
      {{ states('sensor.time') == (states.input_datetime.orario_irrigazione.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}
  condition:
    - condition: state
      entity_id: input_boolean.stato_irrigazione
      state: 'on'
    - condition: template
      value_template: "{{ is_state(state_attr('group.giorni_irrigazione', 'entity_id')[now().isoweekday() - 1], 'on') }}"
  action:
    - service: script.turn_on 
      entity_id: script.irrigazione_vasi
    - wait_for_trigger:
        - platform: state
          entity_id:
            - switch.irrigation_pump
          to: 'on'    
      timeout: 00:00:10
      continue_on_timeout: true

Every 2 days, at what time?

The subsequent example you posted reveals that the scheduled time is controlled by a helper (Input Datetime). You can use a simple Time Trigger for that instead of a lengthy Template Trigger.

automation: 
- alias: Irrigazione Vasi
  initial_state: true
  trigger:
    - platform: time
      at: input_datetime.orario_irrigazione
  condition:
    - condition: state
      entity_id: input_boolean.stato_irrigazione
      state: 'on'
    - condition: template
      value_template: >
        {{ (now() - as_datetime(0)).days % states('input_number.your_interval') | int(1) == 0 }}
  action:
    ... your actions go here ...

The following template determines if the current day is a multiple of 2. Copy-paste it into the Template Editor and experiment with it to see the results it produces.

{{ (now() - as_datetime(0)).days % 2 == 0 }}

Ok thank you, I’ll try to do as you told me and see if the interval works

You marked your own post with the Solution tag. However the example in your post doesn’t meet your requirement for running every 2 days.

Did my example (designed to run every 2 days at the time specified by input_datetime.orario_irrigazione) fail to work? Or did you eliminate the requirement to run every 2 days?