One time password: checking and handling

I wanted a way to use the OTP (one time password) sensor in an automation, but I also wanted an else clause in there to alert me when things go wrong.

Just setup the OTP sensor as described in the docs sensor.otp
You need to, of course, make the script do something usefull but this is the automation

id: py_test
alias: 'OTP checking'
    platform: event
    event_type: telegram_command
      command: '/otpCheck'
   - service: python_script.otpcheck
       key: '{{["args"][0]}}'

and this is the script:

otpEntity = "sensor.otpkey"
key = data.get('key')

# Get the OTP code
otpKey = hass.states.get(otpEntity).state
if (key == otpKey):'telegram_bot', 'send_message', {'title':'*Ok*', 'message': 'w00t'})
else:'telegram_bot', 'send_message', {'title':'*ERROR*', 'message': 'Oops, something went wrong'})

This will allow you to perform actions based on the OTP code, and handle the else scenario as well

1 Like