[OBSOLETE] Sense Energy Monitor

This SmartApp integrates Sense Energy Monitor devices into SmartThings. It requires running a node server on the same LAN as your hub to actually maintain the real-time connection with Sense. Once the connection is set up, the SmartApp will automatically create devices in SmartThings matching your devices in Sense.

A few ways you can use this:

  • Trigger various automations based on Sense devices turning on or off (or by changes in usage amounts)

  • Initiate SmartThings push notifications when Sense devices turn on or off (and restrict notifications to certain modes).

  • Delay push notifications by X minutes to ensure that device really is off. (Example: only notify that the dryer is off if it’s stayed off for at least 15 minutes)

  • Show your Sense usage (individual devices and total usage) on ActionTiles or within the ST mobile app

Installation

Screenshots

image image

image image

Special thanks to blandman, the author of the unofficial Sense API node library I used to build the data collection piece of this.

Notable design info

  • The node server maintains a websocket connection to Sense that receives data every second.
  • Periodically and as devices turn on or off, data is sent to the SmartThings hub via local network calls. No Oauth setup is necessary.
  • The Sense devices in SmartThings are updated near-instantaneously (essentially replacing the IFTTT functionality and a lot more)

Enjoy!

7 Likes

A few notes on this first beta version…

  • The SmartApp does not currently offer the option to control which Sense devices are brought over - for now it’s just grabbing everything. At some point, I will add an interface to exclude devices if desired.
  • The Node server setup is the least user friendly piece, especially for people who have never dealt with Node before. I’m still thinking through better ways to streamline that.
  • I do not have Sense Solar, so I have no idea how that would be handled by this app currently. If someone with Solar would be willing to let me peek at their account for a bit just to see how the data comes in, I could make adjustments where needed.
  • There will be bugs! I’ve been running this myself and using push notifications for a couple weeks, and it’s worked well, but I’m sure I have missed things.

Great work, although I am not sure if I will set this up. I’ve personally found Sense completely unreliable and it misses a lot of data. I’ve seen my Tesla charging and it missing it occasionally, same with AC. On another note, Sense engineers are requesting that you authenticate only every 15-30 mins to get data as it’s causing performance issues:. Not sure if this will impact this smartapp.

I wish Sense would leverage Smartthings for device detection. They just did so with Hue, and It would drastically improve Sense’s core intelligence if they did.

Aside from making the initial connection, this node server holds a websocket open and only re-authenticates in the rare case where Sense closes the connection.

1 Like

This is very cool however not working for me yet. I set up the node.js server and it said it was running and gathering data. However no devices have showed up with the DTH and Smart App installed as instructed.

I know this was few months ago, was wondering if sense is blocking anything? Probably an issue at my end, I’ll keep digging.

Update: I checked the node running and it seems to be successfully getting data from Sense and it says Data successfully sent to SmartThings hub! however looking at sense monitor log, it’s quiet. Seems like my problem is on the ST side with either DTH or App. Guessing DTH.

Not sure what else to look at. added back in log.debug messages to the app which I assume is listening to messages and it never gets a message. I used a sniffer on the LAN and I do see the node sending them. IP looks correct. Not sure if ST is just not accepting it or the data in the packet is off :frowning:

Still no devices created. I’ll try and add one manually to see what happens. (or if anybody has any debug suggestions?

That’s really odd. Where in the SmartApp did you add debug messages? I’m guessing it was the commented out lines around 117? And nothing at all shows up in live logging? What version hub do you have?

I have the v2 hub. I pretty much put back in your log.debug messages to get more but had to remove one that kept going.
|Firmware Version|000.024.00011|
|Hardware Version|Hub v2 US|

I concentrated on the lanEventHandler() and added a “log.debug evt.description” to see if it gets anything. Seems every once in awhile it does but then does nothing else in that function (so I assume headerMap = NULL & body = NULL). Log looks like this:

9:00:05 AM: debug devicetype:04, mac:0017xxxx0F45, networkAddress:C0A8xxx3, deviceAddress:0050, stringCount:04, ssdpPath:/description.xml, ssdpUSN:uuid:2f402f80-da50-1xx1-9b23-001788740f45, ssdpTerm:urn:schemas-upnp-org:device:basic:1, ssdpNTS:

I think those are the Wemo Insights since it comes every 5 minutes. Eventually I do see it as Wemo device:
9:15:01 AM: debug devicetype:04, mac:14918xxxxx11D, networkAddress:C0A8xx35, deviceAddress:C001, stringCount:04, ssdpPath:/setup.xml, ssdpUSN:uuid:Insight-1_0-231803Kxxxx38E::urn:Belkin:device:insight:1, ssdpTerm:urn:Belkin:device:insight:1, ssdpNTS:

but with log.debug messages around 117 and other places, I never gets past (body != NULL )

I assume the node server is working fine with the messages that come out of node.js window (using it on windows 10 with firewall turned off):

Successfully connected to Sense! Data incoming!
2018-10-29 23:25:30 Data successfully sent to SmartThings hub!
2018-10-29 23:26:28 Living Room AC usage changed by -967.6754760742188
2018-10-29 23:26:28 Data successfully sent to SmartThings hub!
2018-10-29 23:26:29 Living Room AC turned off!
2018-10-29 23:27:28 Data successfully sent to SmartThings hub!
etc…

I did confirm the smartapp seems to never get the message in lanEventHandler() and only gets some other random stuff with header and body = NULL every five minutes.
Not sure if it’s ST blocking the message from the smartapp or some other smartapp interfering or taking the message.

Are you familiar with using Postman at all? If so, can you try sending a POST to your hub’s IP? The URL would be http://(yourHubIP):39500/event and you can make the body something like {“testing”: “123”}

Another thing you could try is a different fork of this whole project here: https://github.com/tonesto7/SmartThings_SenseMonitor

@tonesto7 did a ton of work expanding upon this, so it’s possible it might work better for you? At some point, I’m going to merge his changes in - just haven’t gotten around to it yet.

Thanks for the tips. I tried out Postman and got the 202 accepted. I assume the hub is getting it.

Also put the forked version (nice initialization :slight_smile: ) still no go.

I searched all logs and found the Wemo Insights devices using the IP:39500 address a lot. Not sure if that dth for those devices are causing some confliction. Not sure if that’s possible as I’m still learning about the infrastructure of how ST handles incoming.

Looks like more time debugging :frowning:

Could you try enabling OAuth in the Sense SmartApp? I wouldn’t think that should matter, but I noticed it’s enabled on mine.

If you’re seeing Postman successfully send a message, you should definitely see it while debugging in a SmartApp that’s subscribed to all LAN events. Multiple devices can use that same port - in my case I also have my Rainmachine device communicating over the same port…I differentiate the two by parsing either the headers or the message body itself.

This one is a real head scratcher as to why you’re not seeing anything at all. The tough part about all of this is the way the node server is interacting with hub via LAN is not officially documented anywhere, so we’re pretty much on our own.

1 Like

Enabled OAuth for Sense SmartApp but no luck.

Turned back on log.debug at the beginning of the lanEventHandler(evt) to print out the msg. Then did the Postman again and sure enough it picked it up and you can see it in the log.

I guess that means ST is receiving. That may mean something wrong on my node server sending. Possibly Win10 issue (that’s what I’m using at the moment for the node.js).
What system do you use for your node server?

Ok, narrowed it down to the Win10 server in question.

From my laptop (win10 also) the POSTMAN worked and logged in ST. From the Win10 server I had planned to use it did not (even though it reported success).

Something weird is going on between that win 10 server and ST for this I guess. Weird things is that server is running other activities with ST which work fine.

Thanks again for your suggestions and I’ll focus my debugging on why this win10 is failing me.

1 Like

Ok, devices are up using my laptop as a temporary node server :slight_smile: Thanks again Brian ! I knew it was something on my end but couldn’t debug it so fast without your suggestions especially on using POSTMAN. I’m a bit rusty on programming since it’s been awhile but I’m back in it.

Awesome DTH/App.

Now I’ll have to figure out why my normal always on PC packets are not getting to ST. I’m assuming some setting in Win10’s nightmare is doing something even though wireshark shows the packets going… Might be time to set up a separate Linux system to be a server. Wish node.js server can work on Android OS but I’m not so sure that’s being done yet.

1 Like

Glad to hear it! Nice to have someone else using it and seeing how it works! I’d suggest grabbing a raspberry pi - that’s what I’m using to run it.

1 Like

Switched over to RasPi and all problems gone :). Very awesome integration I have to say. Is there a list of future enhancements somewhere? Love to help if I can.

I’m planning on working on optimizing the logic as soon as I release my new Echo Speaks integration

2 Likes

Very cool, thanks Brian and Anthony. Awesome integration.

One cool feature would be to get the current month cost device to display in Action Tiles. Then you can see your current cost at run-time. Not sure if that can be pulled from sense (like you can see in it’s app). And total kwH used in the current month. Then you can start playing with webcore or something to do comparisons to last month and what you are on track of hitting for the current month. Those would really be awesome things to see on Action Tiles. Would love to help if it’s not already done.

Just a thought.

1 Like

Hi, I’m trying to get the node server running on a RPi 3 using Raspbian Stretch (latest). I’m getting an error loading the server.js that says the modules.js file is not found. I’m assuming that maybe the node version may be an issue. What versions of Node and NPM are recommended?

I finally got this working using node 11. I also went a step further and have tonesto7’s fork working as a Docker Container, which was pretty easy to do. Doing so should make issues with Node version much easier to over-come since that can be specified in the Dockerfile. Here were the steps to create and run the docker container. I’ll be forking and updating a branch with this when I get some time.

Install Docker on your host (https://www.docker.com/get-started)

Create a file called Dockerfile in the node_server folder

Contents of the Dockerfile file in node_server folder:
FROM node:11
WORKDIR /app
COPY package.json /app
COPY server.js /app
COPY config.js /app
COPY unofficial-sense.js /app
COPY ecosystem.config.js /app
RUN npm install
COPY . /app
CMD node server.js
EXPOSE 9021

Build the Docker Image:
docker build -t sense-monitor .

Run the Docker Image on mapped port, omit -d to run in the foreground and not detached.
docker run -d -p 9021:9021 sense-monitor

List running Docker processes:
docker ps

To stop a Docker process, get container id from above command:
docker stop

//TODO