Service input_boolean.turn_on not work in Automation

HI all.

I have a problem with a service input_boolean.turn_on and input_boolean.turn_off in automation.
This is my automation.

alias: IrrigazionePy
description: ""
trigger:
  - platform: time
    at: input_datetime.zone1_time1_starttime
    id: startTime1
  - platform: time
    at: input_datetime.zone1_time2_starttime
    id: startTime2
  - platform: time
    at: input_datetime.zone1_time3_starttime
    id: startTime3
  - platform: time
    at: input_datetime.zone1_time4_starttime
    id: startTime4
action:
  - choose:
      - conditions:
          - condition: trigger
            id: startTime1
        sequence:
          - service: input_boolean.turn_off
            data: {}
            target:
              entity_id: input_boolean.zone1_time1_go
      - conditions:
          - condition: trigger
            id: startTime2
        sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: input_boolean.zone1_time2_go
            data: {}
      - conditions:
          - condition: trigger
            id: startTime3
        sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: input_boolean.zone1_time3_go
            data: {}
      - conditions:
          - condition: trigger
            id: startTime4
        sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: input_boolean.zone1_time4_go
            data: {}
  - service: python_script.irrigation
    data_template:
      trigger: "{{ trigger.entity_id }}"
  - choose:
      - conditions:
          - condition: trigger
            id: startTime1
        sequence:
          - service: input_boolean.turn_off
            target:
              entity_id: input_boolean.zone1_time1_go
            data: {}
      - conditions:
          - condition: trigger
            id: startTime2
        sequence:
          - service: input_boolean.turn_off
            target:
              entity_id: input_boolean.zone1_time2_go
            data: {}
      - conditions:
          - condition: trigger
            id: startTime3
        sequence:
          - service: input_boolean.turn_off
            target:
              entity_id: input_boolean.zone1_time3_go
            data: {}
      - conditions:
          - condition: trigger
            id: startTime4
        sequence:
          - service: input_boolean.turn_off
            target:
              entity_id: input_boolean.zone1_time4_go
            data: {}
mode: single

The flow working fine but this action not work

         - service: input_boolean.turn_off  #(or turn_on)
            data: {}
            target:
              entity_id: input_boolean.zone1_time1_go

In the automation trace I have this response

Result:
params:
  domain: input_boolean
  service: turn_off
  service_data: {}
  target:
    entity_id:
      - input_boolean.zone1_time1_go
running_script: false
limit: 10

If I use this instruction in a script, working fine.

Where am i wrong?

Regards,
Marco

Not sure what’s going on there. Your very first service call of the action should, I think, be a turn_on. The second block of code you pasted has indentation issues.

If the idea is to turn on the appropriate input_boolean, run the script, then turn it off again, try this much shorter version:

alias: IrrigazionePy
id: faf3b245-2817-4385-9733-9bb7fde2417a
trigger:
  - platform: time
    at:
      - input_datetime.zone1_time1_starttime
      - input_datetime.zone1_time2_starttime
      - input_datetime.zone1_time3_starttime
      - input_datetime.zone1_time4_starttime
    variables:
      idx: "{{ trigger.entity_id[25] }}"
action:
  - service: input_boolean.turn_on
    target:
      entity_id: input_boolean.zone1_time{{ idx }}_go
  - service: python_script.irrigation
    data:
      trigger: "{{ trigger.entity_id }}"
  - service: input_boolean.turn_off
    target:
      entity_id: input_boolean.zone1_time{{ idx }}_go

The indentation was created by UI automation and the flow is correct.

image

Yes, the first action is wrong, I correct it but have the same result.
I have try your code, is more “light”, but the problem is the same.

Executed: 11 maggio 2023 alle ore 15:28:00
Result:
params:
  domain: input_boolean
  service: turn_off
  service_data: {}
  target:
    entity_id:
      - input_boolean.zone1_time1_go
running_script: false
limit: 10

The turn_on\turn_off not working

This bit from your post is wrong, but probably a pasting error.

image

Why do you think it’s not working? The log you pasted does not show a problem — that’s exactly what a log looks like on my system when it is working.

Executed: 11 May 2023 at 14:34:27
Result:
params:
  domain: input_boolean
  service: turn_on
  service_data: {}
  target:
    entity_id:
      - input_boolean.ch_away
running_script: false
limit: 10

Can you paste the history graph for input_boolean.zone1_time1_go like this:

Yes a cut&paste problem.

I thought it was wrong for: running_script: false
I thought “false” meant not executing the command

In any case this is the history, the boolean has never been activated

image

Are you sure? What are the four lines after 13:00?

Try adding a delay into the action so you can see if it changes. Note that you cannot manually run the automation because of the references to trigger.entity_id — you must trigger it with one of the input_datetimes.

action:
  - service: input_boolean.turn_on
    target:
      entity_id: input_boolean.zone1_time{{ idx }}_go
  - service: python_script.irrigation
    data:
      trigger: "{{ trigger.entity_id }}"
  - delay: "00:03:00"
  - service: input_boolean.turn_off
    target:
      entity_id: input_boolean.zone1_time{{ idx }}_go

You are right!
I’m an idiot, the problem is the python script that fails because I realized now that the shelly it’s supposed to activate is offline, so the python immediately terminates and the boolean goes back to offf

I hadn’t noticed the lines!

Thanks!

2 Likes

We all are at times. At least you have a shorter automation now.

1 Like