RFID Timekeeper

My goal is to make a sort of time-keeper wich logs the coming and going of about 10 people who are working at our place.
With ESPhome i already setup a RFID Tag-reading terminal, in HA i can setup those tags and
my wish is to let HA create a excel file wich will be always updated when a tag was scanned.
In the excel file there should be rfid-id,date,time, status(coming or going).
Is an Automation wich can create a file possible?

Any suggestions/ideas?

You can indeed create an automation which can log event time and RFID to a file using the command line integration. You can even put this file in the public HTTP directory of Home Assistant, so that you can download it from anywhere at any point in time. This file will not be an Excel file, but you can then write a bit of Python to turn this into a CSV file, which can then be imported (or used as a data source) in Excel.

Alternatively you can use the Google Sheets integration to write your row of data on every event out to a Google Sheet.

Hi,
I’d be very much interested in this project.
I also have approximately 10 people, and I need a time punch/time card machine.

I also want to link this to arm/disarm the alarm system.
eg. when the last person leaves the building the alarm will be armed automatically

Hi,

I’ve been reading these:

and

Would it be possible to control a short LED strip with D1 mini or something, that individual LED represents workers (changes colour when they’re in/out).

When all the workers are out, arm the alarm.
And when at least 1 worker come in, disarm.

And then use this to output all the changes to the google sheet to track the working time?

I need help with the first part thou, LED strip and programming the arm/disarm automation.
I got the google sheet working with door sensors logging.

cheers!

i’ve made it!

on esphome i use this code:

substitutions:
  plug_name: esp-rc522-rfid
esphome:
  name: esp-rc522-rfid
  platform: ESP8266
  board: d1_mini
  on_boot:
    priority: 600
    # ...
    then:
      - output.set_level:
          id: rfid_lcd_brightness
          level: 70%
      - output.turn_on: rfid_beep

api:
  password: "xxx"
  reboot_timeout: 0s
  
ota:
  password: "xxxxx"

wifi:
  networks:
  - ssid: "xxxxxxx"
    password: "xxxxxxxxxx"
  ap: 
    ssid: "xxxxxxx"
    password: "xxxxxxx"
  manual_ip:
    static_ip: 192.168.4.2
    gateway: 192.168.4.1
    subnet: 255.255.255.0

captive_portal:

web_server:
  port: 80

logger:
  level: INFO
  baud_rate: 0

text_sensor:
  - platform: homeassistant
    entity_id: input_text.rfid_tag
    name: "rfid lcd"
    id: "rfid_lcd"
  - platform: wifi_info
    ip_address:
      name: ${plug_name}_WiFi IP
    ssid:
      name: ${plug_name}_WiFi SSID
  - platform: template
    name: esp_rc522_rfid_uptime
    id: esp_rc522_rfid_uptime
    icon: mdi:clock-start

#          lcd pin an                         diode                                                                  diode
#          nodemcu pin                  gnd   5v   gnd   tx   gnd  d4   nc   nc   nc   nc   d5   d6   d7   rx   +5v   d8
#                                       gnd   vcc  kontr  rs   rw  e    d0   d1   d2   d3   d4   d5   d6   d7   led+  led-
#
#          rc522                        sda   sck   mosi  miso   gnd   3v3
#          nodemcu pin                  d3    d0    d2     d1                              piep an sd3 (-) +5v (+)
#
#          kommen/gehen schalter an a0
#
#
display:
  - platform: lcd_gpio
    dimensions: 16x2
    data_pins:
      - 14
      - 12
      - 13
      - 03
    enable_pin: 02
    rs_pin: 01
    lambda: |-
      it.printf(0,1,id(rfid_lcd).state.c_str());
      static int i = 0;
      i++;
      if ((i % 2) == 0)
      it.strftime(0,0,"%H:%M   %d.%m.%y", id(homeassistant_time).now());
      else
      it.strftime(0,0,"%H %M   %d.%m.%y", id(homeassistant_time).now());
     
light:
  - platform: monochromatic
    name: "rfid lcd brightness"
    output: rfid_lcd_brightness
    
output:
  - platform: esp8266_pwm
    pin: 15  # Diode!! K an GPIO15, A an LCD-LED K
    frequency: 5000 Hz
    id: rfid_lcd_brightness
  - platform: gpio
    id: rfid_beep
    pin: 10
    
time:
  - platform: homeassistant
    id: homeassistant_time

spi:
  clk_pin: 16
  miso_pin: 05
  mosi_pin: 04

rc522_spi: 
  cs_pin: 00
  update_interval: 0.5s
  on_tag:
    then:
      - homeassistant.tag_scanned: !lambda 'return x;'
      - output.turn_off: rfid_beep
      - delay: 0.1s
      - output.turn_on: rfid_beep
      - logger.log:
          format: "gestempelt: %x"
          args: ['id(kommengehen).raw_state']
          level: INFO
      
sensor:
  - platform: wifi_signal
    name: ${plug_name}_WiFi Signal
    update_interval: 60s

  - platform: adc
    pin: A0
    id: 'kommengehen'
    name: "Kommen_Gehen"
    update_interval: 0.25s

  - platform: uptime
    name: "esp_rc522_rfid Uptime Sensor"
    id: esp_rc522_rfid_uptime_raw
    update_interval: 10s
    on_raw_value:
      then:
        - text_sensor.template.publish:
            id: esp_rc522_rfid_uptime
            state: !lambda |-
              int seconds = round(id(esp_rc522_rfid_uptime_raw).raw_state);
              int days = seconds / (24 * 3600);
              seconds = seconds % (24 * 3600);
              int hours = seconds / 3600;
              seconds = seconds % 3600;
              int minutes = seconds /  60;
              seconds = seconds % 60;
              if ( days ) {
                return { (String(days) +"d " + String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() };
              } else if ( hours ) {
                return { (String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() };
              } else if ( minutes ) {
                return { (String(minutes) +"m "+ String(seconds) +"s").c_str() };
              } else {
                return { (String(seconds) +"s").c_str() };
              }


The coming/going switch is connected to A0, because of no more GPIOs …
The LCD is a 5V LCD with a diode in vcc, to get a good contrast.
the on_tag sensor is send to HA, there is an automation wich decides on tag id who is coming in / going out.
It makes an append-csv-file with date, time and name wich will be sorted in future by an js.
So far it works very well since 02.12.2022.
All our people that work for us have saved their times into that csv file.

Here a sample of HA automations:

alias: RFID-Anja gehen
description: ''
trigger:
  - platform: tag
    tag_id: 85-92-BB-79
condition:
  - condition: numeric_state
    entity_id: sensor.kommen_gehen
    above: '0.2'
action:
  - service: light.turn_on
    target:
      entity_id: light.rfid_lcd_brightness
    data:
      brightness: 1
  - service: notify.filenotify
    data:
      message: >-
        {{now().strftime("%d.%m.%Y")}};{{now().strftime("%H:%M:%S")}};{{
        "gehen"}};{{"Anja"}}
  - service: input_text.set_value
    data:
      value: bye bye Anja!
    target:
      entity_id: input_text.rfid_tag
  - delay:
      seconds: 5
  - service: input_text.set_value
    data:
      value: 'gehen:          '
    target:
      entity_id: input_text.rfid_tag
  - service: light.turn_on
    target:
      entity_id: light.rfid_lcd_brightness
    data:
      brightness: 240

if you wonder why the brighness of the lcd-background-led is set to 1 when rfid-tag is scanned and turnt to 240 : the background led is connected to vcc and gpio, so the less the pwm so brighter the led.
So the display gets dark if nothing happens and gets bright when someone holds the rfid chip to it.

1 Like

to get more sensebility i would like to use the command

rfid.PCD_SetAntennaGain(rfid.RxGain_max);

like it is possible on arduino ide.

Can someone help me with the syntax for esphome?

I need some help…

these entity doesn’t exist anymore in HA,
so i cant use

  - service: input_text.set_value
    data:
      value: bye bye Anja!
    target:
      entity_id: input_text.rfid_tag

anymore in Automation.

I have the feeling that something changes in ESP Home and/or HA after updating everything.
Does anyone has an idea?