Tasker Smart NavBar #4 NFC lights controller

I have talked about Smart NavBar actions for WhatsApp before and the time and location contexts, it’s time to try something new. Tasker 5.7 comes with native NFC actions, so there is no need for plugins any more. This got me the idea to link the Smart NavBar series and present you NFC enabled smart lights controller available in the NavBar. You will be able to scan NFC to display controllable devices in each room and control it directly from the NavBar.

NFC lights controller

I streamlined the original version of my profile to make it easy to add new rooms and devices. Now you can simply scan a new NFC tag to log in to another room or scan the same one to log out. This Smart NavBar action will allow you to keep store the state of the lights (and other devices) and display it via icons.

Getting NFC tags ready

To log in to a room you have to prepare your NFC tag first. Scanned tags return %evtprm() array that stores the tag’s ID and the payload. I created a simple task that you can use to write your room names. Make sure you note the values as you will need to be consistent.

NB Write NFC 
	A1: NFC Tag [  Payload To Write:kitchen Payload Type:Text ]   

Just hoover the phone over the NFC tag and run the task with the modified name.

NFC control profile

The profile consists of 2 parts. One section logs you in (when you are not logged in or when you are logged in to another room), while the other one logs you out from the room. Based on the %evtprm2 value and the state of the %NBroomTag variable one of the following will be performed:

Profile: NB NFC Room 
	Event: NFC Tag [ ID:* Content:* ]
Enter: NB Set Room 
	A1: Variable Set [ Name:%NBroomTag To:off  ] 
		If [ %NBroomTag !Set ]
	A2: If [ %NBroomTag ~ on | %NBactiveTag !~R none|%evtprm2 ]
	A3: Flash [ Text:Logging in please wait Long:Off ] 
	A4: Variable Set [ Name:%NBactiveTag To:%evtprm2  ] 
	A5: Perform Task [ Name:NB NFC %evtprm2  ] 
	A6: Flash [ Text:Logged in to %evtprm2 Long:Off ] 
	A7: Variable Set [ Name:%NBroomTag To:off  ] 
	A8: Stop [ With Error:Off Task: ] 
	A9: End If 
	A10: If [ %NBroomTag ~ off ]
	A11: Variable Set [ Name:%NBactiveTag To:none   ] 
	A12: Navigation Bar [ Left:back[1.0] 
						  Right: ] 
	A13: Flash [ Text:Logged out from %evtprm2 Long:Off ] 
	A14: Variable Set [ Name:%NBroomTag To:on   ] 
	A15: Stop [ With Error:Off Task: ] 
	A16: End If   

Log in to a room

Apart from nice Flash actions telling you about the progress, there are 3 actions crucial to this operation. First, I’m going to set the room name in %NBactiveTag (office, kitchen, none)- this is used to keep track of the rooms that you are in. It’s worth noting that I have added the %NBactiveTag !~R none|%evtprm2 to run this task if you simply scan another NFC tag without logging out.

Then I’m going to perform the action which starts with NB NFC %evtprm2 (room name). Which has the correct NavBar task associated with it.

Lastly, I will change the value of the %NBroomTag to off – as next time I scan the same NFC tag, I want the other condition to run instead.

Log out of the room

To reset your Smart NavBar, you have to sign off first by setting the %NBactiveTag to none. then use the NavBar action to set a default NavBar and change the value of the %NBroomTag to on so the next time the other condition would run.

NFC controller in the NavBar

For each device in the room, I’m running the HTTP Get request. Since my devices are flashed with custom software and have REST API available. You can use sonoff based Tasmota or AFE Firmware on all compatible ESP8266 devices.

NB NFC office 
	A1: HTTP Get [ Server:Port:http://  Path: Attributes: Cookies: User Agent: Timeout:10 Mime Type:text/* 
		Output File:Download/oittm.txt Trust Any Certificate:On Continue Task After Error:On ] 
	A2: Read File [ File:Download/oittm.txt To Var:%result1 ] 
	A3: AutoTools Json Read [ Configuration:Input Format: Json
		Simple Mode: true
		Json: %result1
		Fields: value
		Json Root Variable: whole
		Variable Name: state1
		Separator: , Timeout (Seconds):60 ] 
	A4: HTTP Get [ Server:Port:http:// Path: Attributes: Cookies: User Agent: Timeout:10 Mime Type:text/* 
		Output File:Download/koogeek.txt Trust Any Certificate:On Continue Task After Error:On ] 
	A5: Read File [ File:Download/koogeek.txt To Var:%result2 ] 
	A6: AutoTools Json Read [ Configuration:Input Format: Json
		Simple Mode: true
		Json: %result2
		Fields: value
		Json Root Variable: whole
		Variable Name: state2
		Separator: , Timeout (Seconds):60 ] 
	A7: Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ] 
	A8: Variable Set [ Name:%NBofficestate1 To:%state1  ] 
	A9: Variable Set [ Name:%NBofficestate2 To:%state2 ] 
	A10: Navigation Bar [ Left:back[1.0] 
						  Right:task(NB Bench Toggle %NBofficestate1)[1.0],task(NB Lamp Toggle %NBofficestate2)[1.0] ] 
  • Obtain the status with HTTP Get for each device (vary how, based on your device)
  • Save the output to file
  • Read the file as JSON with AutoTools
  • Update the %NBofficestate(x) variable for each device in the room

Then set the NavBar with composed data. My NavBar config looks like this: task(NB Bench Toggle %NBofficestate1)[1.0],task(NB Lamp Toggle %NBofficestate2)[1.0]

NB Toggle on/off

For each device, I have to create two ON and OFF task which will contain the correct HTTP request, the correct name and the correct icon associated with the task. Since the NavBar looks for the task with the %NB (device name) %NBofficestate(x) then I have to make sure the name is consistent.

TASKER TASK: NB Bench Toggle on
NB Bench Toggle on 
	A1: HTTP Post [ Server:Port:http:// Path: Data / File: Cookies: User Agent: Timeout:10 
		Content Type: Output File: Trust Any Certificate:On ] 
	A2: Variable Set [ Name:%NBofficestate1 To:off ] 
	A3: Navigation Bar [ Left:back[1.0] 
						 Right:task(NB Bench Toggle %NBofficestate1)[1.0],task(NB Lamp Toggle %NBofficestate2)[1.0] ] 

Adding more room and devices

If you want to add another room, all you have to do is to replicate the NB NFC office and modify the HTTP Get requests. You have to remember to create the ON and OFF tasks for each new device in the room. I could possibly do this with arrays, but this would increase the complexity significantly.

Smart NavBar integration

This is a stand-alone version of the Smart NavBar actions. Once I created the standalone versions for each NavBar Task I will show you how to integrate it together. The link to that write up will be up soon!


The Smart NavBar NFC controller shows you how dynamic the NavBar can be. If you are bothered, you can even run the NB NFC (room name) task every minute to get accurate icon changes. You can connect any IoT device using HTTP request, MQTT or NodeRED. While this all is done in a local mode, you could also create access from the WAN. Take a look at other NavBar actions I have created. You can download the Tasker profile from this link.

Pocketables does not accept targeted advertising, phony guest posts, paid reviews, etc. Help us keep this way with support on Patreon!

Mat Zolnierczyk

I am passionate about technology, cycling, and art. This would explain why my bike has more computing power than your average office. I own notenoughtech.com and I write for xda-developers.com and pocketables.com NotEnoughTECH | Facebook | Twitter |YouTube |Instagram | Google+ |Donate |Patreon