mhue.nvim - Control Philips Hue1 Lamps Without Leaving Neovim!
Completely dependency free2!
Control Philips Hue lamps from Neovim!
Based on my earlier project mhue.py.
- List available lamps
- Toggle Lamps on or off
- Retrieve lamp status.
- Change lamp status, like color, brightness, temperature etc.
- Turn lamps on round-robin
- Send Morse Code using your Hue lamps and automatically reset to original state.
This plugin relies only on a modern (>=0.12) version of Neovim.
This program turns your lights into flashing lights. If you, or anyone in the general vicinity of your lamps, have a medical condition that makes you sensitive to flashing lights, do not use this.
{
"ginger51011/mhue.nvim",
opts = {
config_path = "~/.mhue.json", -- Optional
default_wpm = 7, -- Optional, values between 3-15 are nice
}
}You need to do a one-time connection to your Hue Bridge. You will need the IP on the local network for your bridge.
Press the big round button on your bridge and then run this:
:lua require("mhue").quick_setup("<your IP here>")
This will store a username later used for authentication in your config_path.
Here are some example use-cases.
The names are the ones you configure yourself. If you want more descriptive names, configure the lamps in the app.
require("mhue").list_lamps(function(lamps) vim.notify(tostring(lamps)) end)This example uses which-key.nvim, but
you can do the same with normal mappings.
-- Add toggle for each listed lamp
local mhue = require "mhue"
local wk = require "which-key"
mhue.list_lamps(function(lamps)
local add = {}
for _, v in ipairs(lamps) do
table.insert(add, {
"<Leader>m" .. v.id,
function() mhue.toggle_lamp(v.id) end,
desc = "Toggle " .. v.name,
})
end
wk.add(add)
end, function(err)
if err then vim.notify(err, vim.log.levels.ERROR) end
end)Warning
Sending an SOS message, using Neovim or not, can be regulated in your area. Please consult a lawyer before sending publicly visible SOS messages.
local lamp_id = 1
require("mhue").send_morse_msg(lamp_id, "SOS")local lamp_id = 1
require("mhue").send_morse_visual_marked(lamp_id)Warning
Depending on your writing speed, this can be very blinky!
-- Turn lamp 1, 2, 3 on/off round-robin style on each text input
local rr = require("mhue").round_robin { 1, 2, 3 }
if rr then vim.api.nvim_create_autocmd("TextChangedI", { callback = rr }) end-- Lamp on, full brigtness, red picked from CIE 1931 color space
local desired_state = require("mhue.lamp").LampState.new(true, 254, nil, nil, nil, { 0.6756, 0.3191 })
local lamp_id = 1
require("mhue").set_lamp_state(lamp_id, desired_state)Q: Wait, why?
A: Yes.
Q: What are the cybersecurity considerations for this?
A: Don't use this on the public internet. Don't connect to untrusted sources. Don't eat lead paint, even if it is oh so tasty. There is no HTTPS and username (password) is sent in clear text, so only used on a closed network / VPN.
Q: What are the social considerations for this?
A: I've been trying to send messages to my neighbours using this, but I'm not sure they know Morse code...
Q: Wait, dependency-free? You use curl or something right?
A: No, I wanted to try something new so I implemented an small HTTP/1.1
library on top of luv. Why are you
crying? Stop crying. Also don't use the HTTP code for any other use case.
Please. Actually barely use it for this use case.
Q: How much of this was written using AI
A: With the exception of asking some chatbot for pointers on async, nothing! That can be both good or bad!
Q: Can I get commercial support?
A: I want to say yes?
I do not accept any donations. If you however find any software I
write for fun useful, please consider donating to an efficient charity that
save or improve lives the most per $CURRENCY.
GiveWell.org is an excellent website that can help you donate to the world's most efficient charities. Alternatives listing the current best charities for helping our planet is Founders Pledge, and for animal welfare Animal Charity Evaluators.
- Residents of Sweden can do tax-deductable donations to GiveWell via Ge Effektivt
- Residents of Norway can do the same via Gi Effektivt
This list is not exhaustive; your country may have an equivalent.
Footnotes
-
I'm in no way associated with Philips Hue, this was based on public knowledge of their API_ ↩
-
Seriously. It only needs nvim >= 0.12. ↩