AppDemon - how to test code?

Hi,

One very basic question, under IDE (outside of HA) we can simply run a command “python hello_world.py” to see if it works or if there are any errors.

But I am unable to achieve the same under AppDemon, here is the python script I am trying to execute. The script is suppose to send SMS message via Twilio API depending upon state of a boolean input.

type or pastefrom twilio.rest import Client
import appdaemon.plugins.hass.hassapi as hass

class twilio(hass.Hass):
    def initialize(self):
        self.listen_state(self.sendSMS, 0, new="on")

    def sendSMS(self, entity):
        current_state = self.get_state(input_boolean.test_switch)
        if current_state = 1:
            self.executeSMS()
        else:
            logger.info("****************************************")
            logger.info("there is nothing to send for SMS")
            logger.info("****************************************")

    def executeSMS(self):
        # Your Account Sid and Auth Token from twilio.com/console
        # and set the environment variables. See http://twil.io/secure
        account_sid = <blanked>
        auth_token = <blanked>
        client = Client(account_sid, auth_token)
        logger.info("***********************************************")
        logger.info("Python script triggered from automation")
        logger.info("***********************************************")
        message = client.messages.create(body="Sending text through automation.....",from_='+blanked',to='+1blanked')

But after restarting the AppDemon, I do not see any error or output in the logs.
Is there a better way to debug python code for AppDemon that I am not using?

Thanks,

Pankaj

1 Like

Ok, got the code to work with Twilio SMS…partial victory but getting there :grinning:

import appdaemon.plugins.hass.hassapi as hass
from twilio.rest import Client

class testingPM(hass.Hass):
   def initialize(self):
       self.runTest()

   def runTest(self):
       account_sid = <blanked>
       auth_token = <blanked>
       client = Client(account_sid, auth_token)       
       message = client.messages.create(body="Sending text through automation.....",from_='<blanked>',to='<blanked>')
       self.log("Sending SMS: %s", message.sid)

The AppDemon runs an admin dashboard on port 5050 which has a tab for logs, logs helped a ton in getting to bottom of it.

Also learnt that naming python script file “twilio.py” was a bad idea as it collided with so many native files :grinning: