AppDaemon running service issue

I am writing an AppDaemon automation to turn some switches on and off. I’m using the following syntax:

self.call_service("switch.turn_on", entity_id = device_text)    
self.call_service("switch.turn_off", entity_id = device_text)

I get the following errors in the error log:

ValueError: Invalid Service Name: switch.turn_on
ValueError: Invalid Service Name: switch.turn_off

Huh? What am I missing? From the services developer page in HA, those appear to be the correct service names, and I can successfully call them from there.

Also, there seems to be an error in the documentation. This page:
https://appdaemon.readthedocs.io/en/latest/HASS_API_REFERENCE.html#services
states that the syntax for call_service)_ is:

self.call_service(self, service, **kwargs)

But all of the examples don’t include “self” in the arguments, and putting it there causes an error related to incorrect number of positional arguments. Not sure if this is relevant, but thought I’d mention it…

(NB: Yes, I know I can use self.turn_on/self.turn_off. I don’t want to do it that way as the thing I’m writing is more generic than that and the service to call might not always be an on/off. But that’s what I’m testing it with.)

In case it matters, I’m using Hass.io 0.84.2, with the AppDaemon plugin 1.6.0 which implements AppDaemon 3.0.2. The whole thing is running in an ESXI VM.

I have just tried it out, and get the same result as you. I guess everyone uses self.turn_on(), which does work.

Should be

self.call_service("switch/turn_on", entity_id = device_text)    
self.call_service("switch/turn_off", entity_id = device_text)

Regards

3 Likes

Aha! That was it.

Yup, missed that. Was using the syntax from HA, not from the AppDaemon examples.

Thanks.