AppDaemon Q&A

@turboc Ah yeah, I’m still no quite sharp on the calls. Thanks for the corrections!

If I can ask, why’s the second way more efficient?

The handler handles calling HA once when the switch is thrown, rather than every time you reach a point in AD where you want to check for it. Those checks become local variable checks so we don’t have to go to HA every time we check.

FYI - get_state() doesn;t go to HA every time, it maintains a local copy and updates it as events happen. That said, I still prefer your second method - it is more elegant.

Thanks guys!

Another question: What’s the best way of calling a function from another app’s class?

Should I include the other app as a module and then call the function?

There is a built in function for this called get_app(), docs are here.

Thank you so much!

Hey all. Loving AppDaemon! <3

I am wondering if it is possible to create a toggle in HA to enable/disable an app automation (like the basic automations).
Because apps are very dynamic I guess not.

I thought about creating an input_boolean that will appear in the HA main page. Is that the best practice to do that?

Thank you very much :slight_smile:

you can disable/enable any app with an input_boolean and a constraint (see constraints in the API)

you can use turn_on or set_state in AD to adjust the state of devices in HA. You can also change the switches in HA to control which automations run in AD by using get_state.

Do show an example of how to set this up I want to know this one. I’m not a programer just a hack! I need a sample to change and manipulate.

An extract from my appdaemon.cfg. The line of interest to you is constrain_input_boolean…

[bedroom_trv]
module = etrv
class = eTRV
trv_id = 5460
sensor_temp = sensor.bedroom_temperature
slider_set_temp = input_slider.bedroom_temp
select_state = input_select.bedroom_trv_state
power_mode_switch = switch.bedroom_trv_low_power_mode
away_temp = 16
constrain_input_boolean = input_boolean.automatic_temperature
schedule = 06:00:00>21, 08:00:00>17, 21:00:00>21, 23:00:00>18
1 Like

That keeps the entire app from running unless that input_boolean is true. Right? Or does it just impact listening for one input_boolean? That’s new in the latest AD release. RIght?

This is correct.

So if you had multiple automations running in the same app you would need to control it through the application. For example, I have a sunrise_sunset app, that controls the indoor light and outdoor lighting. If I put my house into party mode let’s say, and only wanted that to impact the indoor lighting but leave the outdoor lighting alone, I would need to fall back to keeping track of the state of the control in HA, that sets party mode, by checking or monitoring it’s state within the app. Right?

@gpbenton
Wow that was easier than expected I will try it thanks! Now can that be changed from an input boolean to another condition? Is that in the API and I just haven’t read it yet? :wink:

That is correct.

However, I break my apps into controlling different items, rather than have one controlling multiple things at a certain time.

There is also the problem that you can only have one constrain_input_boolean per app.

I break mine along functional lines. I have sunrise_sunset apps, Christmas Apps, alarm_clock apps, etc, they all control more than one light or set of lights. The fun part is when they start fighting each other. The TV app, dims the lights, but the night time app wants to turn them up, it can be kind of entertaining. LOL

1 Like

https://github.com/home-assistant/appdaemon/blob/master/API.md#callback-constraints

you can also use the constraints from out of the app itselve. (its not new by the way)

just like:

            self.run_at_sunrise(self.set_lights_on,offset=offset1,constrain_days=constraindays,switch=switch)

with contstaintdays

(its not new by the way) - I meant constraints in the appdaemon.cfg file were new. They are. Right?