HomeTaskerTasker Smart NavBar #4 NFC lights controller

Tasker Smart NavBar #4 NFC lights controller

Light on, Light off, Wax on Wax off

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.

TASKER TASK: NB Write NFC
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:

TASKER PROFILE: NB NFC Room
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] 
						  Center:home[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.

TASKER TASK NB NFC office
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] 
						  Center:home[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] 
						 Center:home[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. You can read the tutorial about this now!

Conclusion

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. Let me know how would you use it in this Reddit thread.

Project Download

Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.

PayPal

Nothing says "Thank you" better than keeping my coffee jar topped up!

Patreon

Support me on Patreon and get an early access to tutorial files and videos.

image/svg+xml

Bitcoin (BTC)

Use this QR to keep me caffeinated with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

New to Tasker?

Tasker Quick Start – Getting started with Tasker

0
From newb to not so newbie in 10 min

Best Tasker Projects

How to use Raspberry PI as WOL (wake on lan) server

0
While you could wake up your PC from a mobile directly, having a dedicated server capable of doing so is the best solution. The reason is simple. You can hook up as many devices as you wish with a single endpoint. This is why Raspberry Pi is perfect for this.

How to wake on LAN computers and put it to sleep with Power Menu,...

0
How to Wake on LAN properly via Android, Alexa, Google Assistant and Web

7 awesome Bluetooth keyboard shortcuts for Android

0
7 unique Android shortcuts that you can add to any Bluetooth keyboard.

Smart overnight charging with Tasker

0
Still keeping your phone plugged in overnight? Try smarter overnight charging with this profile

One thing that Join app can’t do and how to fix it with Tasker

0
It's not possible to share the clipboard automatically between join accounts registered to 2 different emails. But you can fix this with tasker.

Essential Guides

Tasker: Seconds into DD:HH:MM:SS (dynamic)

0
It's time to.... ok it's a pun, but I will show you how to master time and convert seconds to DD:HH:MM:SS dynamically

4 ways to organise Tasker projects

0
Keep your Tasker tidy!

A better way to store Tasker credentials

0
The more clever way of managing credentials

Annoyed with dozens of AutoApps populating your app drawer? Here is a fix!

0
Clear your app drawer from the clutter in seconds

Putting AutoTools pie chart to a good use – SSID logger

0
Who wants a piece of the pie (chart)?