Automation using two switches as input

Hi,

I’ve been trying to figure this one out but hit a road block.

Basically I’d like to perform a logical AND operation on the state of two buttons, that when both are at logic 1 (on) will fire off a command.

What I’ve done so far is create two input boolean entities:

input_boolean:
  hdmi_matrix_out1:
    name: "HDMI Matrix Output 1"
    initial: off
  hdmi_matrix_in1:
    name: "HDMI Matrix Input 1"
    initial: off

Then a shell command running curl:

shell_command:
    matrix_out1_in1: "/usr/bin/curl -X POST http://<ip_address>/video.get -d '#video_d out1 matrix=1'"

in the configuration.yaml file.

In the automation.yaml file I created this entry:

  - alias: 'hdmi_matrix_out1_in1'  
    trigger:
      - platform: state
        entity_id: input_boolean.hdmi_matrix_out1
        from: "off"
        to: "on"
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: input_boolean.hdmi_matrix_out1
          state: "on"
        - condition: state
          entity_id: input_boolean.hdmi_matrix_in1 
          state: "on"
    action:
      service: shell_command.matrix_out1_in1

HASS doesn’t find anything wrong with the configuration and reloads just fine. No issues in the log file.

The problem is that upon setting state 1 for both in1 and out1 nothing is happening. I am not sure if the automation conditions are even being evaluated as under Devel -> State ; it shows the automation as ‘off’ while both ‘in1’ and ‘out1’ switches are at ‘on’.

I’ve been reading through many pages in the docs:



…among others but unfortunately haven’t figured out a solution yet. Perhaps the whole automation sequence is incorrect and I should be doing something different?
Originally I had thought about linking in a Bash shell script but I’m sure that this is easily doable within HASS.

Thanks for any suggestions!

There are a couple of things…

the first is:

If the automation shows “off” then the automation will never trigger because the automation is disabled. an automation should always show as “on” so that is able to be triggered even if the automation isn’t actively doing anything. IOW, the “on/off” state doesn’t mean the automation is in progress. It means that it’s enabled or disabled.

So, turn the automation to “on”.

Next the way you have your code set up is that if you turn on input_boolean.hdmi_matrix_out1 before you turn on input_boolean.hdmi_matrix_in1 then the automation won’t trigger because the conditions won’t be met since the automation will only run the actions if both booleans are on when input_boolean.hdmi_matrix_out1 changes state.

If that’s the way you want it then that doesn’t coincide with the statement of the goal:

to make it do what the problem statement says you have to add the other boolean to the trigger as well. And to streamline things a bit since a boolean can only ever be “on” or “off” there is no need to use the “from:” line. And since conditions are always “and” by default unless you specify otherwise then you can get rid of that too:

  - alias: 'hdmi_matrix_out1_in1'
    trigger:
      - platform: state
        entity_id: input_boolean.hdmi_matrix_out1
        to: "on"
      - platform: state
        entity_id: input_boolean.hdmi_matrix_in1
        to: "on"
    condition:
      - condition: state
        entity_id: input_boolean.hdmi_matrix_out1
        state: "on"
      - condition: state
        entity_id: input_boolean.hdmi_matrix_in1 
        state: "on"
    action:
      service: shell_command.matrix_out1_in1

The way it is above it will trigger no matter which boolean turns on first or last. As soon as the second one goes to on then the conditions are met and the actions will run.

1 Like

Thanks so much!!! :slight_smile: :slight_smile:
Now it works.

I originally did put both entities into the trigger portion but then reading further suggested that the operation was OR’ed and not AND’ed. Of course I didn’t have any conditions setup at the time.
It was a long day too :stuck_out_tongue: - just glad it works now! Thanks again…

1 Like