Appdeamon set state of zigbee deconz light

Hi,
I am building my first app to dim a light using a remote and the AppDeamon v4.0.3, but I am having an issue when setting the new brightness attribute. The entity updates in hassio, but it doesn’t seem to update properly because:

  • The bulb doesn’t change its brightness
  • The brightness attribute of the light entity is updated with the new value. However all other attributes disappear. This can be seen in the following 2 screenshots:
    before pressing the remote button

    after pressing the remote button

I suspect I am not setting the state correctly. Something to do with the self.set_state() function, however I cannot see what I am doing wrong. Do you have any suggestions?
Also, it would be interesting to hear alternative ways to dim the lights with AppDeamon and remotes.

Thanks in advance!

I have created the following code:

import appdaemon.plugins.hass.hassapi as hass

class button_pressed(hass.Hass):
  
  def initialize(self):
    self.listen_event(self.myaction, "deconz_event")


  def myaction(self, entity, data, kwargs):
    
    remote_id = "rwl021_15"
    button_id = 2000
    if data["id"] == remote_id and data["event"] == button_id:

      #the appropriate button has been pressed
      li = "light.techo_office"
      b = self.get_state(entity_id=li, attribute="brightness")
      n = self.increase_brightness(b)
      self.set_state(entity_id=li, state="on", attributes={"brightness": n})
      self.log(n)
  
  def increase_brightness(self,b):
    """
    increase brightness by step within limits
    """
    step = 50
    max = 255
    new = b + step
    if new > max:
      return max
    else:
      return new
More Details
  • Raspberry Pi 4
  • HassOS 3.13
  • AppDeamon plugin 0.2.5
  • Light is an IKEA TRAFIDRI bulb E27 WS opal 980lm firmware 1.2.217

set_state only changes the internal state in Home Assistant, it does not communicate with the device.

You need to use

self.call_service("light/turn_on",  entity_id="light.your_entity_id",  brightness=your_required_brightness)

or

self.turn_on("light.your_entity_id", brightness=your_required_brightness)

Thanks Tomas, it works great :slight_smile: