Support for conditions in Scripts?

Is there any support for conditional execution in scripts available or planned?

I’d like to push some of the logic I have in automation into scripts, mainly for re-use purposes. For example, I would like a script that does something like the following (pseudocode)

set house mode to "evening" (I have an input_select that tracks a mode variable)
if anyone present then
  turn on downstairs lights
else
  turn on single front light
  if (heating_enabled) then
    turn on heating
  endif
endif

A script like the above I can use for 3 things:

  1. Run automatically at sunset
  2. Manual activation if someone is home
  3. Run automatically when someone arrives home

At present I can create rules for the automatic actions, but it will take several entries instead of 2, and there is no way to run that same script manually.

I took a look at templates but I don’t think they can help here - please let me know if I am wrong.

As an alternative to scripts supporting this, is there a way to call out into a python snippet that just contains the logic without having to create a new domain?

If this isn’t available or planned I’ll add it to the feature request forum.

1 Like

See the website: Use templates to decide which service to call

1 Like

Thanks! That gets me a lot closer to where I wanted to be - this page didn’t come up in any of my searches, thanks for pointing it out.

I’ve found (especially with out new community site) that using google site searches works a treat now.

Example: Search for site:home-asistant.io MY SEARCH TERM and it brings up everything relevant for the site, blog and the community.

2 Likes

Above mentioned link is no longer valid, can someone please show where is it?
Thanks

I found the link if someone needs it: