Dynamically created Switch not working in Lovelace

I am trying to have an appdaemon app create a switch, that would then be used by the user through Lovelace to activate a service.

The app then listens for the state of the switch, and if on, starts a process.

My issue is this:

  • creation of the switch - OK, no issue

  • callback of listen_state works, as i tried setting the state directly through the developer tools in HA

  • however, calling the switch.turn_on service through developer tools or through pressing a card on Lovelace do not work.

Any ideas please?

Please share the code that you’re using to turn the switch on/off.

I use a lovelace button entity to call the turn_on service:

show_name: true
show_icon: true
type: button
tap_action:
  action: call-service
  service: switch.turn_on
  target:
    entity_id:
      - switch.reset_tplink_router
    device_id: []
    area_id: []
entity: switch.reset_tplink_router
name: Reset Router
hold_action:
  action: call-service
  service: switch.turn_off
  target:
    entity_id: switch.reset_tplink_router

I then listen from appdaemon:

self.listen_state(self._callbackResetRouter, “switch.reset_tplink_router”)

The callback works, when I change manually the state in Developer tools > States, but not through Developer Tools > Services > switch > turn_on