Compare commits

...

2 Commits

Author SHA1 Message Date
68684d9410
Added hue groups for kitchen and living room lights controlled by hue switch
All checks were successful
Build and deploy / Build application (push) Successful in 3m50s
Build and deploy / Build container (push) Successful in 1m21s
Build and deploy / Deploy container (push) Successful in 35s
2025-01-28 22:49:37 +01:00
746e19eb8c
Use own struct to deserialize hue switch state and added hold actions 2025-01-28 22:48:02 +01:00
5 changed files with 71 additions and 3066 deletions

3056
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -64,7 +64,6 @@ tokio-util = { version = "0.7.11", features = ["full"] }
tracing-subscriber = "0.3.16"
uuid = "1.8.0"
wakey = "0.3.0"
zigbee2mqtt-types = { version = "0.4.0", features = ["debug", "philips"] }
air_filter_types = { git = "https://git.huizinga.dev/Dreaded_X/airfilter", tag = "v0.4.4" }
[dependencies]

View File

@ -19,7 +19,6 @@ impls = { workspace = true }
serde = { workspace = true }
reqwest = { workspace = true } # Use rustls, since the other packages also use rustls
anyhow = { workspace = true }
zigbee2mqtt-types = { workspace = true }
axum = { workspace = true }
bytes = { workspace = true }
thiserror = { workspace = true }

View File

@ -6,8 +6,8 @@ use automation_lib::event::OnMqtt;
use automation_lib::mqtt::WrappedAsyncClient;
use automation_macro::LuaDeviceConfig;
use rumqttc::{matches, Publish};
use serde::Deserialize;
use tracing::{debug, trace, warn};
use zigbee2mqtt_types::philips::{Zigbee929003017102, Zigbee929003017102Action};
#[derive(Debug, Clone, LuaDeviceConfig)]
pub struct Config {
@ -25,6 +25,30 @@ pub struct Config {
#[device_config(from_lua, default)]
pub right_callback: ActionCallback<HueSwitch, ()>,
#[device_config(from_lua, default)]
pub left_hold_callback: ActionCallback<HueSwitch, ()>,
#[device_config(from_lua, default)]
pub right_hold_callback: ActionCallback<HueSwitch, ()>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "snake_case")]
enum Action {
LeftPress,
LeftPressRelease,
LeftHold,
LeftHoldRelease,
RightPress,
RightPressRelease,
RightHold,
RightHoldRelease,
}
#[derive(Debug, Clone, Deserialize)]
struct State {
action: Action,
}
#[derive(Debug, Clone)]
@ -60,7 +84,7 @@ impl OnMqtt for HueSwitch {
async fn on_mqtt(&self, message: Publish) {
// Check if the message is from the device itself or from a remote
if matches(&message.topic, &self.config.mqtt.topic) {
let action = match serde_json::from_slice::<Zigbee929003017102>(&message.payload) {
let action = match serde_json::from_slice::<State>(&message.payload) {
Ok(message) => message.action,
Err(err) => {
warn!(id = Device::get_id(self), "Failed to parse message: {err}");
@ -70,12 +94,10 @@ impl OnMqtt for HueSwitch {
debug!(id = Device::get_id(self), "Remote action = {:?}", action);
match action {
Zigbee929003017102Action::LeftPress => {
self.config.left_callback.call(self, &()).await
}
Zigbee929003017102Action::RightPress => {
self.config.right_callback.call(self, &()).await
}
Action::LeftPressRelease => self.config.left_callback.call(self, &()).await,
Action::LeftHold => self.config.left_hold_callback.call(self, &()).await,
Action::RightPressRelease => self.config.right_callback.call(self, &()).await,
Action::RightHold => self.config.right_hold_callback.call(self, &()).await,
_ => {}
}
}

View File

@ -59,6 +59,47 @@ automation.device_manager:add(HueBridge.new({
},
}))
local kitchen_lights = HueGroup.new({
identifier = "kitchen_lights",
ip = hue_ip,
login = hue_token,
group_id = 7,
scene_id = "7MJLG27RzeRAEVJ",
})
automation.device_manager:add(kitchen_lights)
local living_lights = HueGroup.new({
identifier = "living_lights",
ip = hue_ip,
login = hue_token,
group_id = 1,
scene_id = "SNZw7jUhQ3cXSjkj",
})
automation.device_manager:add(living_lights)
local living_lights_relax = HueGroup.new({
identifier = "living_lights",
ip = hue_ip,
login = hue_token,
group_id = 1,
scene_id = "eRJ3fvGHCcb6yNw",
})
automation.device_manager:add(living_lights_relax)
automation.device_manager:add(HueSwitch.new({
name = "Switch",
room = "Living",
client = mqtt_client,
topic = mqtt_z2m("living/switch"),
left_callback = function()
kitchen_lights:set_on(not kitchen_lights:on())
end,
right_callback = function()
living_lights:set_on(not living_lights:on())
end,
right_hold_callback = function()
living_lights_relax:set_on(true)
end,
}))
automation.device_manager:add(LightSensor.new({
identifier = "living_light_sensor",
topic = mqtt_z2m("living/light"),