meaning dt is a fixed and standard defined object in Python and the ‘last_triggered’ attributes isnt the same?
could I try to set another variable, maybe choose my own, and use that?
still don’t understand why that would only cause errors at first run, and not later on though. This scripts is running all the time, and only throws these errors at boot, albeit in abundance …
Oh… that might be because the object may not have a last triggered datetime object on startup. Just perform a check to verify that it has the key inside the dictionary hass.states.get(‘automation.mode_selection’).attributes.has_key(‘last_triggered’)
i will certainly thanks. your post was the first mentioning has_key, and so i need to learn more on that .
anyways, the time declaration 1 post up does work.
most of the time.
thanks again, and if you notice any bits to be optimized : don’t hesitate… appreciate all the expert guidance i can get.
has_key is a dictionary method. You should take one of those free online coding python classes. Something like codecademy. It will teach you all the basics of python, dictionary work would be covered in that. You can get the tutorials done relatively quickly.
this is needed for each dt = statement in the larger summary.py, cant set it globally in the script?
there is no way of telling the system to adapt this system wide, so a separate import for this (and other) python scripts even necessary.
I ask because it seems rather inefficient if one needs to state all over the system one is in a timezone, while a systemwide setting should take car of that…?
…
doing do renders this error, before ive even added the other lines in the script.
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/homeassistant/components/python_script.py", line 166, in execute
exec(compiled.code, restricted_globals, local)
File "summary.py", line 7, in <module>
ImportError: __import__ not found
Apparently HA doesn’t support imports with scripts… that’s kinda dumb. Anyways, you can probably just use the datetime object. I hope they have that imported into their environment.
popping up.
Could it be anything else i need to set somewhere, cant imagine i am the only Hassio user encountering this problem… @mviezzer did you ever change the timezone settings? Why cant we import as @petro suggests? Manually adjusting the timezone seems rather ridiculous …
It’s because they are executing the python files with the exec() function. This is a limitation of that call. It’s possible to add the import built in but it can only be done on the interpreters end. I’m guessing there is a reason they avoid it.
since all other methods proved impossible, i would like to try this.
How do i do the check? do i just drop it in the script, or should it be accompanied with several if, then else scenarios?
if has_key: continue
if ! has_key: do this
just asking…