Vacation facet challenge 2023: Turtles
![](https://blinkingrobots.com/wp-content/uploads/2024/01/Holiday-side-project-2023-Turtles.png)
TL;DR: If in case you have lights managed by Shelly dimmers and/or through a Philips Hue bridge, Turtles may probably be a helpful challenge for you. It’s moderately easy to arrange and the code is small and straight-forward so it could be straightforward to hack at in case you like that form of factor, however it is vitally restricted in performance in comparison with one thing like Home Assistant.
The itch
My spouse and I not too long ago accomplished a renovation challenge of an enormous a part of our home. Nearly all the new lights have been managed by Shelly dimmers, that are Wi-Fi connected and have some easy APIs for programmability. A few lights wanted extra energy than the Shelly dimmers may deal with, and the electricians used some no-name Zigbee dimmers for this.
After all this prompted an instantaneous itch to need to have the ability to management all of the lights directly from my smartphone, create scenes and so forth.
I poked a bit on the Shelly APIs, they’re quite simple to make use of so long as you’re on the identical Wi-Fi, and I ordered an off-brand Wi-Fi/Zigbee bridge through Aliexpress, figuring it would arrive earlier than the vacation break and this may very well be a pleasant challenge throughout the vacation break.
I additionally took a take a look at Residence Assistant and another present dwelling automation platforms. Rationally, I may need been higher off going with Residence Assistant, which has ready-made integrations with Shelly, Zigbee dimmers, and possibly 1000’s of different machine varieties, however I wished full management and hackability, and I most well-liked to spend time constructing my very own system reasonably than studying and customizing Residence Assistant and perhaps by no means getting it to work like I would like it to.
Scratching it
The AliExpress cargo arrived simply earlier than the vacations! Sadly, the order didn’t comprise a Zigbee bridge however reasonably a Bluetooth Low Vitality (BLE) bridge. The AliExpress people brushed me off once I despatched them a photograph exhibiting the packaging of the unsuitable machine… oh nicely, that’s one thing like $20 down the drain ($8 for the factor itself with transport, and the remainder to Icelandic customs and postal authorities… don’t get me began).
Fortunate for me, my spouse had purchased a Philips Hue starter set for our son as a Christmas current, and it comes with a bridge which in a short time and simply found the opposite Zigbee lights! The Hue could be very hackable, too, with simple APIs and a bunch of unofficial documentation across the Web. The one difficult bit was that evidently the Hue bridge will change its MAC tackle once in a while, so assigning it a static IP in our dwelling router didn’t work – a few days later it offered as a brand new MAC tackle and subsequently acquired a special IP. Ultimately it was easy to implement SSDP discovery.
My programming language of alternative as of late is Elixir (together with Erlang and JavaScript) and that’s what I applied Turtles in. The de facto commonplace internet framework for Elixir is known as Phoenix. It’s actually good, however the default generator for a brand new challenge does create a veritable ton of every kind of recordsdata and configuration, a lot of which I don’t want in a easy challenge like this… however which I haven’t gotten round to eradicating.
To make use of Turtles, go get the source code, set up asdf, create a file named tconfig.secret.exs
within the config
listing, set static IPs for all of your Shelly lights in your house router, and doc all of the lights you need to management within the tconfig.secret.exs
file just like the beneath:
config :turtles,
zones: [
"Foyer",
"Kitchen"
],
dimmers: [
{"foyerrecessed",
%{name: "Forstofa inngangur", type: :shelly, zone: "Foyer", ip: "192.168.1.90"}},
{"foyerindirectled",
# Hue device unique IDs can be found at
# http://{ip address of bridge}/api/{Hue bridge username}/lights
%{name: "Foyer indirect LEDs", type: :hue, zone: "Foyer", bridge: :hue1, unique_id: "04:11:84:ff:13:43:75:a3-01"}},
{"kitchenbenches",
%{name: "Kitchen worktops", type: :shelly, zone: "Kitchen", ip: "192.168.1.96"}},
{"kitchenisland",
%{name: "Kitchen island", type: :hue, zone: "Kitchen", bridge: :hue1, unique_id: "03:11:84:ff:13:12:75:a1-03"}},
],
bridges: %{
# For particulars on getting the username, see
# https://www.burgestrand.se/hue-api/api/auth/registration/
#
# The unique_id may be discovered at http://{ip tackle of bridge}/description.xml
# underneath the <serialNumber> key.
hue1: %{sort: :hue, unique_id: "abcdef01234", username: "HUEBRIDGEUSERNAME"}
}
You may get fancy with the way you run Elixir, constructing an Erlang launch and/or placing every little thing right into a Docker container, however from my perspective for a local-WiFi system like this you may merely run it in growth mode as follows:
cd ~/turtles # assuming that is the place you retrieved the code to
iex -S combine phx.server
Perhaps run it in a display screen
session that you could detach from and reattach to later, on an always-on previous Linux laptop computer in a closet, related to the identical Wi-Fi because the lights and bridge, in fact.
Compulsory screenshots
I’ll finish with some compulsory screenshots exhibiting the UI.
Let me know in case you strive it! It was simply to scratch my very own itch, however nonetheless could be enjoyable if it’s helpful for somebody.
Fundamental display screen – management lights, select scenes
Create a scene; give it a reputation and select which lights it is going to have an effect on, and it’ll later apply the identical state to lights as they at the moment have
Handle scenes; thus far all you are able to do is delete however I need to add reordering and renaming.