Project CE Cloud Lighting Part 3 - Touch 10 UI & Nodejs Code

We are starting to get serious now. We have our TP-Link light installed and setup on Kasa. Now we just need some Nodejs code and a Touch 10 UI to finish it off. Our Touch 10 interface looks something like this:


Our focused here is on the lights button. It's pretty simple with a panel pictured below:


I have yet to add the dimmer function in my Nodejs code but built the UI anyway. Seeing as I am the only user of this system, I think that's okay. The On/Off button is a slider which generates an event of 'on' or 'off'. Yep it's that simple.

For my slider I have given it the ID of "office". Now, whenever there is a event fired off the widgetId will be "office".




As with all of the projects involving CE building the UI typically takes less than 10 minutes but it's still fun to build and test them out. For Node code I took a previous project and have just made some adjustments and added some new code.

https://github.com/voipnorm/CEKasa

The CEKasa repo contains 3 files to make the project work. Our .env file to host are passwords and usernames, and the server and endpoint files. The endpoint file is an adaptation of the endpoint file  from https://github.com/voipnorm/CEbusyLightOmega/blob/master/endpoint.js.

What you will notice with the new endpoint file is some lines that are not required are commented out. This is because we will bring all our code together in a later post to build a room controller on our Pi. Now you get it:). I need more material to write about, that's right.

So what's the difference between the two projects you may ask? Well its below. The new monitorWidget function is looking for our Touch 10 events when you move the slider.


--Script--
--Script--

Once it has seen an event it emits its own event to the listener in the server.js file below which fires the light function turning on or off our lights.

--Script--
--Script--


Not a terribly complicated piece of code but it works.

There you have it folks, an inexpensive room light controller. In this project I am only controlling 1 light but this can be expanded to as many lights in the room as you like. I left the dimmer out for now. If you want to have a go, let me know your results in the comments below.

Final thoughts.


This was a fun project to put together. It's also pretty inexpensive with a bulb costing around $20. If you haven't realized already we are building what is a pretty inexpensive room controller using our Webex room system and a Raspberry Pi. A typical room controller system can cost anywhere from $2000 and up and to date we have spent less than $500 if you include the HDMI switcher from a previous project. While this does not include the cost of our room system of course which you would need anyway,  we are just taking full advantage of everything we can do with it combined with our Pi.

Hope your enjoying these project posts. It's a great way to get started programming with Pi, Webex Room devices and Nodejs.

VoIPNorm

Previous posts:

Intro to project:

https://voipnorm.blogspot.com/2019/09/project-ce-cloud-lighting-part-1.html

Working with Kasa cloud:

https://voipnorm.blogspot.com/2019/09/project-ce-cloud-lighting-part-2.html

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.