Make 2 functions interdependent

hello everyone, I am currently controlling my fan heater either via a Node red dashboard or via the voice command from Google. However, if I switch on the fan heater via Google for example, the switch will logically remain on "Off". Can I install a function here that also switches on the switch when activated via Google?


What works and what doesn't work?
Does either method turn on heater?

Both work for themselves. But I want that as soon as I control the heater via google the switch goes on on.
And the other way round, when the switch goes to on, google should also go to on



Here's where I tap out, I know nothing about feeding into google. Maybe some one else can weigh in.

This is one of the reasons why it’s good practice to implement a command and a state topic independently of each other when using mqtt to send commands to things that have a state. Your esp listens on the command topic and confirms any state change no matter the source on the state topic.
You would than put a mqtt in node in front of the ui switch described to said state topic. You have to set the dashboard ui switch node to set its state from the incoming message and not pass it through as not to create a loop.
This way your ui switch will always represent the actual state of your esp.
This is also what all the ready made esp firmwares like tasmota and esp-easy or commercial systems that rely on mqtt like shellys implement as their topic structure.


To add some detail to that, configure an mqtt node to pick up the status from the hardware and feed that into the UI switch node, with a change node to configure the on/off values to match the switch if necessary. Set the switch to not pass through and configure it to show the state of the input. Then the switch will always show the state of the hardware whoever updates it.