Set state without communicating with device?

Ok, I’m using this to synchronize the HA state with my wall remotes, so when I turn on a lamp using the wall remote the state in HA changes even though the lamp itself doesn’t tell HA that it was switched on (I’m using 433 Mhz devices). This is a description on how I configured it.

First step is to add your wall remotes to HA. For me, they are autodiscovered by HA since I have them added to my /etc/tellstick.conf and telldusd knows about them and listen to events for them. When I press the wall remote, I can see it changing in HA. Next step is to get the state replicated to the actual lamp/outlet that the wall remote controls.

Add an appdaemon app as .homeassistant/apps/remotesync.py:

import appdaemon.appapi as appapi

#
# Sync remotes and switches so the switches have the correct
# status (on/off) when triggered by the remote from outside HA.

#
# Args:
# switch: entity ID of switch
# app name: entity ID of remote to sync with

class RemoteSync(appapi.AppDaemon):

  def initialize(self):
    self.listen_state(self.state_change, self.name)
    self.log("RemoteSync to %s" % self.args["switch"])

  def state_change(self, entity, attribute, old, new, kwargs):
   if new != old:
     self.set_state(self.args["switch"], state=new)

As you can see, I’m using set_state() to just set the state without actually sending the state to the device.

Now, in appdeamon.cfg I instantiate this app like this:

[switch.remote_garage_b]
module = remotesync
class = RemoteSync
switch = switch.utebelysning_uppfart

[switch.remote_kitchen_b]
module = remotesync
class = RemoteSync
switch = switch.taklampa_kok

Here, I’m basically telling AppDaemon how I have paired by wall remotes with lamps - the remote named switch.remote_garage_b controls the lamp named switch.utebelysning_uppfart, and so on.

Now, whenever the remote switch.remote_garage_b changes state, it sets the state of switch.utebelysning_uppfart to the same value.