Only changing state of switch, no action

Finding a way to change the state of a switch within automation.yaml without taking any action.

Now I have:

  • alias: ‘Woonkamer met remote inschakelen’
    trigger:
    platform: state
    entity_id: switch.remote1
    action:
    • service: light.turn_on
      data:
      entity_id:
      - light.woonkamer1
      - light.woonkamer2
      - light.woonkamer3
      brightness: 50
    • service: switch.turn_off
      data:
      entity_id:
      - switch.remote2
      - switch.remote3

But the service: switch.turn_off actually fires the action, triggering another action for the remote2 and remote3.

The only thing I want is to ‘deactivate’ the status of the remote2 and remote3 switches. Only change the state to off.

Something like this:

- service: switch.STATE_OFF
  data:
    entity_id: 
      - switch.remote2
      - switch.remote3

Is this possible in some way?

(please do not discuss the code, I have good reasons to use this solution :slight_smile: )

By not specifying a state, the automation will get triggered by any state change to switch.remote1
STATE TRIGGER
Triggers when the state of a given entity changes. If only entity_id is given trigger will activate for all state changes, even if only state attributes change.

Thank you for the reply, but I think you misunderstood my question. (or mayby my question was to complex :slight_smile: )
Another try:

How do I change the state of switch.remote2 to ‘off’ (in the action section), but not trigger an event.

As an example the script below.
Presuming remote1, 2 and 3 are all ‘on’.
When pressing the off-button on switch.remote1 , switch.remote2 must set to ‘off’, but must not trigger the event for switch.remote2. So switch.remote3 stays in state ‘on’.

  • alias: ‘Remote1’
    trigger:
    platform: state
    entity_id: switch.remote1
    to: ‘off’
    action:
    service: switch.turn_off
    entity_id: switch.remote2 ## << This triggers the script below and is not what I want. Just set the state to off.

  • alias: ‘Remote2’
    trigger:
    platform: state
    entity_id: switch.remote2
    to: ‘off’
    action:
    service: switch.turn_off
    entity_id: switch.remote3

(again, please do not discuss the code :slight_smile: )

you can switch off the automation in the first part :

- alias: Remote1
  trigger:
    - platform: state
      entity_id: switch.remote1
      to: off
  action:
    - service: homeassistant.turn_off
      entity_id: automation.remote2
    - delay: 00:00:03
    - service: switch.turn_off
      entity_id: switch.remote2 ## << This triggers the script below and is not what I want. Just set the state to off.
    - service: homeassistant.turn_on
      entity_id: automation.remote2

or use input_boolean in combination with conditions

Hi,

See if the following works for you (use the IP of your HA; you will need curl installed). It will change the state in HA but won’t actually trigger the switch to off (as I think it would need state to be “Off” instead of “OFF”)

curl -X POST -d '{"state": "OFF"}' http://127.0.0.1:8123/api/states/switch.remote2

Brilliant!! This is working, even without the delay.

Now I investigate the other sugestion with the input_boolean.

@Petrica
Appreciate your answer. But I think I got it the way DvD77 described.

May I ask where should I put this command for executing?

You can run it from terminal or set a command line switch (https://www.home-assistant.io/integrations/switch.command_line/)

However, depending on what you need to accomplish, there might be better ways.

Thanks!
I want to change the state of my fan which is both controlled by Broadlink RM pro and the remote of the fan itself so that can correspond to the actual state of the button color.
I have add a power monitor plug used for judging the state. But I can’t find a better way to change the state of the entity: switch.fan_power

I’m pretty much in the same situation except that I plan to use Tasmota IR with both IR blaster and IR receiver placed near the fan instead of Broadlink RM (as Broadlink doesn’t do passive recording of IR codes, while Tasmota IR would update HA with all IR commands received case the IR physical remote was used).

I’ve tried Tasmota IR on both split AC and cheap fan with a regular NodeMCU and separate IR blaster and receiver and it works fine (at least with the split AC as it successfully recognized most commands that I needed to setup the HVAC component).

The fan remote uses toggle instead of discrete commands which is not very useful as it is not easy to know the state; as you mentioned, a power monitor plug would provide feedback when it is working, however I don’t know if it would reliably identify different fan speeds or swing motion.

Afterwards, I was looking for something more elegant and ordered these to go with WeMos/Lolin mini boards https://www.aliexpress.com/item/32891173618.html

There is an integration to change not only the state but any attribute of an entity. https://github.com/pmazz/ps_hassio_entities

I also ran into the same issue with my IR-controlled AC. Trying to ‘correct’ the status of the AC created an infinite loop (because when I corrected the state the on/off would fire and make it out of sync again).

I solved it by creating input_boolean.AC_status, and tied the switch.AC status to that. When the AC is manually controlled, an energy monitoring plug detects the change and then the input_boolean.AC_status is updated which changes the switch.AC without sending the on/off commands.

Configuration.yaml:

##AC as a switch entity
#boolean helps to enable watchdog automation to toggle switch.ac w/out triggering the on/off command
input_boolean: 
  ac_status:
    name: AC Status
    icon: mdi:air-conditioner
switch:
  - platform: template
    switches:
        living_room_ac:
          friendly_name: AC
          icon_template: "mdi:air-conditioner"
          value_template: "{{ is_state('input_boolean.AC_status', 'on') }}"
          turn_on:
          - service: script.turn_on
            entity_id: script.ac_power
          - service: input_boolean.turn_on
            entity_id: input_boolean.ac_status
          turn_off:
          - service: script.turn_on
            entity_id: script.ac_power
          - service: input_boolean.turn_off
            entity_id: input_boolean.ac_status

Value_template ties switch.AC to the input_boolean.AC_status. The switch.AC on/off commands also update the input_boolean.AC_status.

AC Watchdog correction automation:

alias: "[AC] Watchdog to correct AC on/off status"
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.ac_power_outlet_active_power
    for:
      hours: 0
      minutes: 0
      seconds: 5
    id: AC turned On
    above: 0.8
  - platform: numeric_state
    entity_id: sensor.ac_power_outlet_active_power
    for:
      hours: 0
      minutes: 0
      seconds: 5
    id: AC turned Off
    below: 0.8
    enabled: true
condition:
  - condition: or
    conditions:
      - condition: and
        conditions:
          - condition: trigger
            id: AC turned On
          - condition: or
            conditions:
              - condition: state
                entity_id: switch.living_room_ac
                state: "off"
              - condition: state
                entity_id: input_boolean.ac_status
                state: "off"
                enabled: false
            alias: Either AC or AC_status are off
        alias: Turned on but AC is off
      - condition: and
        conditions:
          - condition: trigger
            id: AC turned Off
          - condition: or
            conditions:
              - condition: state
                entity_id: switch.living_room_ac
                state: "on"
              - condition: state
                entity_id: input_boolean.ac_status
                state: "on"
                enabled: false
            alias: Either AC or AC_status are off
        alias: Turned Off but AC is On
action:
  - if:
      - condition: trigger
        id: AC turned On
    then:
      - service: input_boolean.turn_on
        data: {}
        target:
          entity_id: input_boolean.ac_status
    enabled: true
  - if:
      - condition: trigger
        id: AC turned Off
    then:
      - service: input_boolean.turn_off
        data: {}
        target:
          entity_id: input_boolean.ac_status
mode: single

Triggers based on power consumption whenever the AC is turned on/off. You’ll need to correct this for your specific AC’s power consumption and it might not work depending on your AC unit. Then conditions check to make sure that the status is incorrect, then actions correct the input_boolean.AC_status which then updates the