Could someone point me in the right direction? I’m trying to save when my door is locked by using an automation to run a python script to save the time my “lock” was last triggered:
from datetime import datetime now = datetime.now() timenow = now.strftime('%I %M %p') hass.states.set('sensor.locktime', timenow)
If I replace:
It prints exactly what I want (ie 06 18 PM).
My lock sensor is basically a door sensor that is activated when the bolt is thrown (link here).
I just can’t get the python script to create the state. I appreciate it’s probably to do with what a state can be saved as. I could get it working with datetime.now() but that was not a usable value as I also want to call it from a custom Alexa skill through an intent script so I need it to read “06 18 PM” and not “18:18:179939393”.