Save the last person who opens the door with RFID

Hi,

I have an RFID system to open my front door. So I have write a python script to retrieve the last person who opened the door (from a CSV URL). Now I would like to save it in HA to display it in Lovelace and have an history but I don’t now exactly how to do that.

I guess I have to create a sensor type entity to store a string ? How can I create one without using a specific platform ? Can I create it directly from python ?

When I will have my entity, I will probably do an automation script to trigger the python script on each door opening. But how can I store the value in my entity (probably with hass.states.set) ?

Thank you for your help

An input text entity is almost certainly what you want. You can then update that using an automation.

Thanks Tinkerer

I’m trying to do some progress but I think I have a new problem. I just see that python_scripts run in a sandbox env so I can’t import urllib2 in my python code. I need this to retrieve CSV data from my RFID door system.

Is there a way to force it or should I use another way to do this (but which way) ?

do you have MQTT running

you could sent it via that

No I’m not using MQTT (my house is mostly KNX).

I’m not sure to understand MQTT but I can’t see how it will work in my case. My RFID system can’t send anyhing so I’m pretty sure I need a Python script (or other script) somewhere to retrieve the value from the CSV file. I also don’t want to run a script externally. I really would like to have everything in HA.

If I’m wrong, can you please explain a bit further what I should do with MQTT ?

Thanks for your help

Maybe the file sensor to read the last line of the csv?
Or you can run a python script without the ‘python_scripts’ component with command_line sensor

I’m not sure the file sensor will work because my CSV file is available by HTTPS only and need authentication. I also need to post process the line to have exactly what I need.

command_line seems to be interesting … I just need to be able to send value back … I will try this.

Thanks you

It’s working with command_line

I just change my script to write the name of the user on standard output and add :

sensor:
  - platform: command_line
    name: 'Last door unlock'
    command: 'python3 /config/external_scripts/get_mobotix_log.py'

command_line call the script every 60 sec by default. I will now search if I can start an update manually so I can use a longer interval and ask for update directly after the door has opened (I have a binary_sensor for this).

Note : on Hassio we also need to install python3 :

apk add --no-cache python3

Thanks again

You can use a large scan_interval for your sensor and update manually with the homeassistant.update_entity service