Skip to content

ginger51011/mhue.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Features

  • 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.

How Does It Work

This plugin relies only on a modern (>=0.12) version of Neovim.

Warning

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.

Installation

LazyNvim

{
  "ginger51011/mhue.nvim",
  opts = {
    config_path = "~/.mhue.json", -- Optional
    default_wpm = 7, -- Optional, values between 3-15 are nice
  }
}

Connecting to your Hue Bridge

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.

Usage

Here are some example use-cases.

List All Lamps with ID

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)

Create Keybindings to Toggle Any Lamp

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)

Send an SOS Morse Code Message

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")

Send Marked Text as Morse Code Message

local lamp_id = 1
require("mhue").send_morse_visual_marked(lamp_id)

Turn Lamps on Round-Robin on Each Input

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

Turn Lamp Red

-- 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)

IFAQ

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?

Support

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

  1. I'm in no way associated with Philips Hue, this was based on public knowledge of their API_

  2. Seriously. It only needs nvim >= 0.12.

About

Neovim Plugin to Control Philips Hue Lamps

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages