this works fine, but I really never like hard coded variables. Couldn’t something like
'/local/activities/{' '}.png/gif'.format(state.state.replace(' ','').lower()),
be possible? Of course the above is not correct, but it shows what I am looking for.
Or a go between like:
'/local/activities/{' '}.png'.format(state.state.replace(' ','').lower()) or '/local/activities/{' '}.gif'.format(state.state.replace(' ','').lower()),
understand,
fear the python environment never allows these imports:
Error executing script: __import__ not found
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/homeassistant/components/python_script.py", line 166, in execute
exec(compiled.code, restricted_globals, local)
File "summary.py", line 9, in <module>
ImportError: __import__ not found
have adapted the above to only check for the ext, and leave the name of the picture in the final statement:
ext = 'gif' if state.state == 'Activity1' else 'png'
or in this situation doesn’t work the way you think it does.
Your if statement would always result in ‘gif’ being selected because your or statement is being analyzed like this:
(state.state == 'activity') or ('activity4')
'activity4' is always True because a string only resolves false when it’s empty. And your string is hardcoded as 'activity4', which is not empty. So You essentially have this as an if statement: