Service: switch.turn_on is toggling a custom switch instead of turning it on only

Hi Guys

I have some custom switches, i want to turn on a few of them using a script. I’m using switch.turn_on but it seems like its toggling the switches i.e. if the switch is already on, calling the turn_on service is turning it off. Any idea why or how i should be doing this differently ?

this is my switch config:

switch:
  - platform: mqtt
    name: "Garage Bypass"
    command_topic: "paradox/control/zones/Garage"
    state_topic: "paradox/states/zones/Garage/bypassed"
    state_on: "True"
    state_off: "False"
    payload_on: "bypass"
    payload_off: "clear_bypass"

this is the service call:

service: switch.turn_on
target:
  entity_id: switch.garage_bypass

The HA config seems fine.
Have you checked on what is behind the MQTT switch if sending “bypass” while the door is already “bypasssed” doesn’t clear it?

ah ! you are right, nothing to do with the switch, if i send a bypass payload to the command topic using MQTT explorer it reverses the current state like a toggle.

Any idea how i prevent the switch from duplicating the command?

You can trap this in the automation calling the script, can’t you? Basically, don’t turn it on again if it’s already on.

thanks for advice, i used choose events to check if the switches are off before sending the bypass commands.