Toggle Flip Flop on Arduino with MQTT


Trying to get a button card to every time pressed it would send an “ON” topic to my Arduino.
As the same flip flop is also controlled by a hardware button, as it has to work without home assistant running.
Have got the linking to work but the topic is staying as active.
So to get the flip flop to change I have to make other button to send “OFF” before I can change state of Flip flop.

My card code:

type: button
  action: call-service
  service: mqtt.publish
    topic: SW1
    payload: 'on'
    retain: false
name: SW1 ON

Have now found out the solution to my issue.

As I was using a compare to translate the text from ON to true it remained in ON/true state until something else was sent to the channel.
Now the ON is routed straight to the flip flop and it works as i want.
I.E. every time I press the button card i get a pulse to flip flop and it changes state.