I got my automations converted over and I’m trying to do the same for some scripts. Basically I use the script as an action, “Bedtime” for example is just a button I use to trigger a bunch of things. What’s the best way to convert that over to AppDaemon?
i dont know what call a button.
i use an input boolean to activate actions.
and in appdaemon you then just use listen_state for the input_boolean and it does the trick.
Can you show an example of your code please?
import appdaemon.appapi as appapi
import os
import datetime
import tempfile
import subprocess
class dashboard(appapi.AppDaemon):
def initialize(self):
tempfile.tempdir = '/mnt/usbdrive/tmp'
self.listen_state(self.update_now,"input_boolean.update_recepten_now")
def update_now(self, entity, attribute, old, new, kwargs):
if new == "on":
cmd = [
"sudo",
"rsync",
"-r",
"--delete",
"--update",
"/mnt/backup/recepten",
"/mnt/usbdrive/pi/appdaemon/appdaemon/conf/custom_css"
]
with tempfile.TemporaryFile() as f:
subprocess.call(cmd, stdout=f, stderr=f)
f.seek(0)
#output = f.read()
self.turn_off(entity)
self.log ("recepten gekopieerd")
this is an app that i use to update a dir on my pi compared to a dir on my pc.
as soon as the boolean is set to on it does the action and after that it sets the boolean back to off.
1 Like