SwitchBot in Openluup (was: Smaller and local alternative to MicroBots)
-
I have a need to just push a button, since I can't hack the thing at the moment. I know there's MicroBot, but they're bluetooth, requires and hub and are not local.
I'm OK with BT or an additional hub, but I really really want local control.
Anyone? Thanks!
-
if Microbot.is is what you are talking about... their whole business model is to get clients to rely on their clown servers for a price to actuate a button pusher... not a fan of the concept. Maybe replace the button with a your own button which would have a zwave relay?
-
Ehm... dont know what you're exactly asking... but I use D1 mini and flash with tasmota via "tasmotizer". That way I have all kind of options, switch, relay, sensors, counter, etc. It connects via WiFi and is small...
@sender said in Smaller and local alternative to MicroBots:
but I use D1 mini and flash with tasmota via "tasmotizer"
I have many of them across the house, mainly to get fancy sensors (distance, humidity, light, pressure, etc), and I integrate them with my own MQTT to luup bridge, plus my virtual plugins.
Anyway, this is an appliance I can't hack at the moment, since it's still under warranty. I've ordered two and will try to integrate via BT. SwitchBot has an open BT API, documented and supported by Home Assistant, so it should be easy to just get the script and replicate it with some luup calls or whatever I'll come with
-
So, I received my units and start thinkering. So far, one is in place, while I need to build a support for the other.
Code is just a small node js app I built around a node library. Seems to work, and I'll report more in the future. Too bad the official hub has no local apis. I can't understand why smart people don't realize internet is not a available everywhere as in their offices... -
People don't learn fast enough. I have seen this being a larger contributor to the bankruptcy of so many startups.... Great/brilliant ideas, destroyed by cloud dependance and the cost/reliability problems/complexity it involves eventually signifying the end of the project and a lot of products dumped in the garbage or best case, a lot of customer frustration. You can probably send them the feedback to let them know...
-
So, mission accomplished. I wrote a very basic node app running on my Linux box. I'm using this library because I'm more comfortable with Javascript than Pyton: https://github.com/futomi/node-switchbot
But it's missing the ability to use password protected SwitchBots, so I will probably patch it or move to the Python one, depending on how many spare time I have in the coming weeks.
Node server is very simple:
const http = require('http'); const url = require('url'); const Switchbot = require('node-switchbot'); const requestListener = function (req, res) { const queryObject = url.parse(req.url, true).query; res.writeHead(200); let device = null; if (queryObject == undefined || queryObject.id == undefined) return res.end('Please specify an id'); const switchbot = new Switchbot(); switchbot.discover({ id: queryObject.id, quick: true }).then((device_list) => { if (device_list == undefined || device_list.length == 0) { console.log('#device: notfound'); res.end('no device'); } device = device_list[0]; console.log('#devicefound: ' + device.modelName + ' (' + device.address + ')'); return true; //device.connect(); }).then(() => { console.log('#device:press'); return device.press(); }).then(() => { console.log('#device:waiting'); return switchbot.wait(1000); }).then(() => { console.log('#device:disconnecting'); return device.disconnect(); }).then(() => { console.log('Done.'); res.end('OK!'); }).catch((error) => { console.error(error); res.end('error: ' + error); }); }; const server = http.createServer(requestListener); server.timeout = 5 * 1000; server.listen(5002); console.log('#http:started');
just call http://ip:5002/?id=mac and you're good to go. I just used my virtual device plug-in to have two virtual switches. It's already integrated into Alexa, WAF is high. Another thing removed from my long standing TODO list
-
Ok, must say. Before I was using tasmota. But since I discovered esphome.io that is now my primary start for automation devices. So easy, so cheap and so reliable!
Easily manageable via home assistant addon... -
Ok, must say. Before I was using tasmota. But since I discovered esphome.io that is now my primary start for automation devices. So easy, so cheap and so reliable!
Easily manageable via home assistant addon... -
@sender I'll flash a new device and try it. I must say I'm ok with tasmota, since I'm using mqtt and I already know the message format, but I'm here to test new things, after all.
@therealdb using esphome and in my case together with homeassistant make mqtt hassle unneeded. It automatically includes the homeassistant api. If the esphome device is part of the same subnet it is auto discovered and entities are auto populated in hass. If not in same subnet need to manually add an esphome integration per device (ip address). Other thing you need to take care of then it is "pinging" devices instead of mdns (all in manual but good to know) for "online status". I have in 1 week around 15 wifi D1 minis as sensors, nextion displays (touchscreen "wallmote quad" but cheaper and better), 4 and 8 relay boards for sprinkler, etc etc. So easy!
-
Yep, I underestimated those cheap wifi devices, until I started to buy many of them, just for testing. While I prefer Zwave for "serious" work, since I have 3 access points on my home (and one outside), Wifi coverage is really good and their traffic is very low anyway, so I'm somewhat sold, especially for fancy sensors and/or difficult to reach zones for my Zwave mesh.
-
So, mission accomplished. I wrote a very basic node app running on my Linux box. I'm using this library because I'm more comfortable with Javascript than Pyton: https://github.com/futomi/node-switchbot
But it's missing the ability to use password protected SwitchBots, so I will probably patch it or move to the Python one, depending on how many spare time I have in the coming weeks.
Node server is very simple:
const http = require('http'); const url = require('url'); const Switchbot = require('node-switchbot'); const requestListener = function (req, res) { const queryObject = url.parse(req.url, true).query; res.writeHead(200); let device = null; if (queryObject == undefined || queryObject.id == undefined) return res.end('Please specify an id'); const switchbot = new Switchbot(); switchbot.discover({ id: queryObject.id, quick: true }).then((device_list) => { if (device_list == undefined || device_list.length == 0) { console.log('#device: notfound'); res.end('no device'); } device = device_list[0]; console.log('#devicefound: ' + device.modelName + ' (' + device.address + ')'); return true; //device.connect(); }).then(() => { console.log('#device:press'); return device.press(); }).then(() => { console.log('#device:waiting'); return switchbot.wait(1000); }).then(() => { console.log('#device:disconnecting'); return device.disconnect(); }).then(() => { console.log('Done.'); res.end('OK!'); }).catch((error) => { console.error(error); res.end('error: ' + error); }); }; const server = http.createServer(requestListener); server.timeout = 5 * 1000; server.listen(5002); console.log('#http:started');
just call http://ip:5002/?id=mac and you're good to go. I just used my virtual device plug-in to have two virtual switches. It's already integrated into Alexa, WAF is high. Another thing removed from my long standing TODO list
@therealdb Thanks for the write up. I managed to setup it up with the Bot and is working. Now I just have to figure out how to write a .py and use mqtt to send the battery status over to Home Assistant.
The Switchbot Curtain is available. Do you think this will work as well? Atm, home assistant does not support the curtain.
-
I’m updating the battery to luup, so it should be doable. I think you may do the same for ha.
The curtain is supported, so this should be easily implemented.
@therealdb Thanks for the reply. Would you mind writing up commands for open and closing of curtain? I am not familiar with this code.
-
Someone over there has tried adding the curtain with the switchbot integration, but it does nothing. No response.