Using NFC Tags in Home Assistant to Create Reminders in Google Calendar

Portrait of Rod Alcidonis

Rod Alcidonis

Published on October 11, 2022

Subscribe to my YouTube channel
Buy me a beer
A picture of a white circular NFC Tag

This automation uses an NFC tag to create a reminder on my Google Calendar to change the Family Room Lock’s batteries in six months. I am using Appdaemon to program the automation, which is one of the automation engines in Home Assistant, and the Home Assistant Google Calendar integration.

Part I

This automation requires that you first configure the Google Calendar Integration in Home Assistant. To configure the Google Calendar, follow the below steps in Home Assistant:

  • Go to “settings.
  • Click on “Devices & Services Integrations, devices, entities and helpers.”
  • Click on “add integration.”
  • In the “Search for a Brand Name” box, type-in “Google.”
  • Then, select the “Google Calendar” option and follow the prompts to configure the integration in your Home Assistance instance.

For additional assistance with configuring the calendar integration, please read the official Home Assistant documentation.

Part II

You need to add an NFC tag in Home Assistant to configure this automation. To add your NFC tag in Home Assistant, follow the below steps:

  • Download the Home Assistant Android or IOS app on your phone.
  • Go to “settings” in Home Assistant.
  • Click on “TagsSetup NFC tags and QR codes.”
  • Click the “Add Tag” button to add the NFC tag to your Home Assistant instance. You should select the option to read-write in order to generate an ID for the tag.
  • Give the NFC tag a name of your choosing.
  • Copy the “Tag_Id” as you will need to incorporate this information into your app.

Please note: if you try to add the NFC tag using your desktop computer, you will not see the option to write onto the tag to generate a “Tag_ID.”

Part III

You are now ready to create the Appdaemon app. This part of the code should be placed in your Appdaemon Apps.yaml file as per the Appdaemon API. This is the minimum procedure to create an App in Appdaemon. If you need additional assistance with this step, please watch my Youtube Video on how to create an app in Appdaemon, or further consult the Appdaemon API before moving to the next part of the code.

The first line of the code is the name of the app in Appdaemon. The second line of the code name module is the name of the Python file which contains the code for our automation. The third line is the class, which is the actual Python code for our automation. Because this is “Yaml” code, the spaces to the left of the words “module” and “Class” are required. The fourth line holds the “Tag_ID” for my NFC cag.


Reminder Tags:
  module: reminder_tag
  class: ApplianceReminder
  tags:
    family_room_lock_tag: "48c578f3-2e56-41cf-34b1-f3d3ce7d100d"

Part IV

You have now completed the preliminary steps of the automation. You have configured your Google Calendar Integration, you have added an NFC tag in Home Assistant, and you have created the associated Appdaemon app. Next, we will write the logic of our automation using Python codes.

To setup my Appdaemon app, I will first import the Appdaemon Python library. Second, I will create a subclass of the Appdaemon library. Then, I will initialize the app in Appdaemon. I covered that information in the YouTube Video on how to create an Appdaemon app in Home Assistant. The lines that begin with “#” is a commented line in Python. I have inserted the complete code below the commented portion.

#import the library
import appdaemon.plugins.hass.hassapi as hass
#Import the Python date module
from datetime  import date
#Import dateutil module. You will need to use this module to calculate a date into the future. such as, six months from today.
from dateutil.relativedelta import relativedelta
# Create the subclass.
class ApplianceReminder(hass.Hass):
#Intialize the subclass
	def initialize(self):

We then need to create an event listener in Appdaemon to monitor the date change on the device sensor. The event that Appdaemon is monitoring is called “tag_scanned.” in Home Assistant. This event listener will be listening for each tag scan in Home Assistant. For this automation, we will use the “Tag_ID” in our code to identify the tag that was scanned. The reference to “Self.tag_scan_activate” is the callback method, or function that will be activated when a tag is scanned. To read more about the listener method or the call back method, please consult the Appdaemon API.

# Listener method
		self.listen_event(self.tag_scan_activate, "tag_scanned")

Next, we need to create another Appdaemon listener but this time a state change listener, as we will be monitoring the state of the date change attribute of the sensor we are monitoring. This will make more sense once we actually create the sensor in Home Assistant. For now, just make a note of this.

The name of the sensor that we will be creating is “”sensor.family_room_lock_monitor”. This sensor is to monitor an NFC tag to remind me in my Google Calendar to change the batteries in the lock six months from the day the tag was scanned.

The reference to “self.family_room_lock_create_reminder” is another callback method for the state listener. This is the method that will contain the code to create the reminder on our Google calendar. This method is dependent on the tag being scanned. Once the tag has been scanned, it will change the future date on the sensor being monitored to trigger this callback method.

# state listener
		self.listen_state(self.family_room_lock_create_reminder, "sensor.family_room_lock_monitor", attribute = "state")
#Create callback method
	def tag_scan_activate(self, event_name, data, kwargs):# Assign today's date to a variable using the datetime module that we imported.
		today = date.today()
#Calculate six months from today as my reminder date using the datetime and the relativedelta from the dateutil module.
		six_month_from_scan_date = date.today() + relativedelta(months =+6)
#Copy the family room tag id from the Appdaemon "apps.yaml file" so I can use it in my automation
		family_room_lock_tag = self.args["tags"]["family_room_lock_tag"]
# Check whether the family_room_lock_tag was in-fact scanned.
		if data["Tag_ID"] == family_room_lock_tag:
# If the family_room_lock_tag has been scanned, and it was the first time that it had been scanned, we will create a sensor in Home Assistant called "Sensor.family_room_lock_monitor." This is the sensor I mentioned that we would be creating. It is necessary to create a sensor because NFC tags are not represented as sensors in Home Assistant and thus, we cannot monitor their state.

The sensor will include three different attributes: the date that the tag was scanned, the future date with which to create the reminder, and a friendly name for the sensor. I am passing the today variable to the set_state method as the first attribute. We created the today variable in the first line of code for this method, and the six months from today variable for the reminder date, which I called “six_months_from_scanned_date”, and then the friendly_name for the sensor.

Appdaemon will create the sensor in Home Assistant if it is the first time you are scanning the particular tag and calling the method. Otherwise, it will only update the attributes of the sensor if there had been a change.

# Create the family room lock monitor sensor
			self.set_state("sensor.family_room_lock_monitor", state = today, attributes = {"friendly_name": "Family Room Door Lock", "Six Month From Today": six_month_from_scaned_date})

Next, we need to create the calendar entry with our callback method. This is the method that we passed to the state change listener. This method contains the code to create the calendar entry in Home Assistant, using the six months from today attribute as the reminder date.

# Create calendar entry
	def family_room_lock_create_reminder(self, entity, attribute, old, new, kwargs):# Call the Google Calendar create service in Home Assistant
		self.call_service("google/create_event", summary= "Change batteries on "+ self.friendly_name(entity), start_date= self.get_state(entity, attribute = "Six Month From Today").replace("/", "-"), end_date= self.get_state(entity, attribute = "Six Month From Today").replace("/", "-"), entity_id = "calendar.Gcal_family_calendar")

I used the “.replace() method when I called the get_state method with the six month from today attribute. This is a Python method to modify or reformat a string. The reason I had to do so is because the date was initially formatted with a “/” and the calendar integration only accepts a “-” in order to not throw an error. I removed the “/” and replaced it with a “-“.

If all went well, now every time you scan the particular tag, it should create a reminder on your google Calendar using the six month from today date as the reminder date, or however long you decide to set the reminder date. You can use this automation to create a reminder to change batteries, appliance filters, and other appliance parts that must be rotated on a schedule.

Please consider subscribing to our newsletter so you are the first to receive future smart home automations in your inbox.

Complete Code

The complete code is as follows:


import appdaemon.plugins.hass.hassapi as hass
from datetime  import date
from dateutil.relativedelta import relativedelta # package to get six months from today

class ApplianceReminder(hass.Hass):
	def initialize(self):
		self.listen_event(self.tag_scan_activate, "tag_scanned")
		self.listen_state(self.family_room_lock_create_reminder, "sensor.family_room_lock_monitor", attribute = "state")

#Callback method to process tag scan
	def tag_scan_activate(self, event_name, data, kwargs):
		today = date.today()
		six_month_from_scan_date = date.today() + relativedelta(months =+6)
		family_room_lock_tag = self.args["tags"]["family_room_lock_tag"]
		if data["tag_id"] == family_room_lock_tag:
			self.set_state("sensor.family_room_lock_monitor", state = today, attributes = {"friendly_name": "Family Room Door Lock", "Six Month From Today": six_month_from_scan_date})

#Callback method to create calendar entry
	def family_room_lock_create_reminder(self, entity, attribute, old, new, kwargs):
		self.call_service("google/create_event", summary= "Change batteries on "+ self.friendly_name(entity), start_date= self.get_state(entity, attribute = "Six Month From Today").replace("/", "-"), end_date= self.get_state(entity, attribute = "Six Month From Today").replace("/", "-"), entity_id = "calendar.Gcal_family_calendar")

Leave a comment

Your email address will not be published. Required fields are marked *