Automation condition doesn't work

I have that configuration, but it triggers also if binary_sensor.pompa_piscina is off , also tried without and codition by simply list all conditions

- alias: "Auto Override Piscina ON"
  trigger:
     platform: state
     entity_id: binary_sensor.supero_potenza
     from: 'off'
     to: 'on'
     for:
       seconds: 5
  condition:
     condition: and
     conditions:
       - condition: state
         entity_id: binary_sensor.supero_potenza
         state: 'on' 
         
       - condition: state
         entity_id: binary_sensor.pompa_piscina
         state: 'on'
         
       - condition: state
         entity_id: binary_sensor.pressostato_pozzo
         state: 'off'
         
       - condition: state
         entity_id: switch.override_piscina
         state: 'off'
  action:
     - service: homeassistant.turn_on
       entity_id: switch.override_piscina

If you copied that correctly then I’m surprised it does anything at all besides generate an error. Your spacing is off in a few places.

Spacing in config is correct, that’s a copy/paste error, now i will correct in original post

A few observations/comments:

You don’t need the first condition, because it won’t trigger if that binary_sensor is not still on.

You don’t need the last condition, because turning on a switch that is on doesn’t do anything.

If you’re turning on a switch you should probably use the switch.turn_on service. It’s more efficient than the homeassistant.turn_on service.

You don’t need condition: and, because by default if you provide a list of conditions they are "and"ed.

If the automation is triggering, then binary_sensor.pompa_piscina must be on at that moment in time. Otherwise the automation would not trigger.

Some explanations:

The first condition is like a “double check”, so I want to check if is still on

Last condition comes from my environment, that switch acts like a toggle, so on/off command are the same, if state is on and i’ll fire on it became off… (Example: a re-trigger when it’s already on)

I’ve also tried without condition: and but there is no change.

The problem is that there’s the action also if binary_sensor.pompa_piscina is off

That check will happen at the time the binary sensor is on because it caused the trigger to match. It cannot fail.

Ok, removed, same problem

I wouldn’t expect this to change anything.

You should check the logs. I can’t see how the actions in that automation can run if the binary_sensor is off.

Unless something is triggering it manually. E.g., you can do that from the UI, but I think you would know if you had done that. :wink: But there’s also an automation.trigger service. Is there a possibility that something is calling it?

Either way, check the logs and you should be able to see if the state of binary_sensor.pompa_piscina is on or not at the time the automation runs, or if something called the automation.trigger service right before.

which component/debug level I have to set for automation troubleshoting?

i’ve set:

logger:
  default: critical
  logs:
    urllib3.connectionpool: critical
    requests.packages.urllib3.connectionpool: critical
    homeassistant.components.binary_sensor.ping: error
    homeassistant.components.switch.command_line: error
    homeassistant.components.automation: debug

but only automation messages are:

2018-09-15 16:35:02 INFO (MainThread) [homeassistant.components.automation] Executing Auto Override Piscina ON Debug

actual conf is (also changed name):

- alias: "Auto Override Piscina ON Debug"
  trigger:
     platform: state
     entity_id: binary_sensor.supero_potenza
     from: 'off'
     to: 'on'
     for:
       seconds: 5
  condition:
     - condition: state
       entity_id: binary_sensor.pompa_piscina
       state: 'on'
     - condition: state
       entity_id: binary_sensor.pressostato_pozzo
       state: 'off'
  action:
     - service: homeassistant.turn_on
       entity_id: switch.override_piscina

but also manual trigger overrides conditions

I would temporarily set the default level to info.

completely unreadable setting at default level, too many entities and mqtt update

Search the log for relevant entries, e.g., using grep. Or try looking at the logbook.

Nothing strange in logs,
“solved” using appdaemon instead of automations,
also by appdaemon logs anything appears to be correct