Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
658 commits
Select commit Hold shift + click to select a range
f0141f1
clippy + enable all kitchen lights
Nov 14, 2024
6c85f98
logging changes
Nov 15, 2024
b28f9bf
fix: do not send xy to lamps that do not support it
Nov 15, 2024
5dca7fe
Add rustfmt and autofmt
evavh Nov 16, 2024
147db49
Set kitchen to debug mode: change drastically every hour
evavh Nov 16, 2024
4e7f45b
fixes affector order decoder + add data_source tests
Nov 17, 2024
5ab51fd
ratelimited logging now per msg +globla limit
Nov 17, 2024
41b2c74
removed leftover spammy info call
Nov 18, 2024
9af3fad
Add extensive but efficient trace logging (as warn)
evavh Nov 17, 2024
7e75b2d
Fix lights not responding after ~1h (tested)
evavh Nov 22, 2024
11b313c
Rename vars for clarity
evavh Nov 17, 2024
e292c3d
Move lamp items to their own submods
evavh Nov 17, 2024
d259fe2
Move LampState to its own mod
evavh Nov 17, 2024
3e02a09
Restrict LampState to lamp mod
evavh Nov 17, 2024
ebff315
Add setter for lamp model for consistency
evavh Nov 17, 2024
4ecf068
Make model fns least pub and remove unused warnings
evavh Nov 17, 2024
bbebc35
Fix clippy pedantic lints
evavh Nov 17, 2024
1aeadac
Prefix all lamp items with mod name for consistency
evavh Nov 17, 2024
fe74f01
Inline LampState struct in Lamp struct
evavh Nov 19, 2024
4f1105d
Replace Change with Property
evavh Nov 19, 2024
b9adaed
Remove obsolete PartialEq for Lamp
evavh Nov 19, 2024
dc6b71e
Refactor send timeout fns, untested
evavh Nov 20, 2024
8b5dccc
Fix rewrite of sent tracking, only sending due changes
evavh Nov 21, 2024
1e91e3b
Add model to needed when it is changed from known
evavh Nov 21, 2024
10b5218
Make lamp have either temp or xy, not both
evavh Nov 22, 2024
bbfb0a1
Clamp color temp to possible values for model
evavh Nov 22, 2024
2b8c4d7
Apply feedback
evavh Nov 22, 2024
a19e3ab
Add Online property and logging sub (unused)
evavh Nov 22, 2024
a447382
Set to testing settings and add tracing
evavh Nov 23, 2024
99c5ee3
Switch to clean session and resubscribe when reconnecting
evavh Nov 23, 2024
808e2d6
Revert "Switch to clean session and resubscribe when reconnecting"
evavh Nov 23, 2024
7b7ac8a
Hardcode model
evavh Nov 24, 2024
ee8e2aa
Reduce iterating over hardcoded light names, cleanup
evavh Nov 24, 2024
4a33fb9
Parse z2m publish error to Online state update
evavh Nov 24, 2024
a1fe16e
Parse bridge events to Online state updates
evavh Nov 24, 2024
b751a42
Only send diff when lamp is online
evavh Nov 24, 2024
1468dfc
Add logging for Online state
evavh Nov 24, 2024
8a5013b
Fix resend timeout and set kitchen to normal settings
evavh Nov 26, 2024
2925367
Clean up ZB logs
evavh Nov 26, 2024
763c033
Merge pull request #40 from dvdsk/zigbee-bridge
evavh Nov 26, 2024
64d5e9c
Change time match SB to work with minutes
evavh Nov 26, 2024
e4183b6
Add basic logic to SB for light button processing
evavh Nov 26, 2024
36f7083
Make color less extreme and switch log to ceiling
evavh Nov 27, 2024
e3ed86c
overhauls logger, not done just changing method at this moment and ne…
Nov 27, 2024
3d12461
tracing ratelimiter implemented in Filter::event_enabled
Nov 27, 2024
49c8572
Merge branch 'dev'
Nov 27, 2024
c9cb6f0
fix warnings
Nov 27, 2024
be59d6f
finish merge
Nov 27, 2024
f8b45c7
removing ratelimited_logger object
Nov 27, 2024
420ff16
remove last object based ratelimited logger
Nov 27, 2024
b88e503
Make color less extreme and switch log to ceiling
evavh Nov 27, 2024
9454464
adds debug statements to dserver watch + stronger ratelimits
Nov 28, 2024
b2f21c4
Merge branch 'main' of github.com:dvdsk/HomeAutomation
Nov 28, 2024
c676e98
fix overflow when device sampling is dur::max
Nov 28, 2024
b28fb68
add affector status + fix sending of orders
Nov 28, 2024
14ed8ff
update embassy version
Nov 28, 2024
6df8db7
fixes is_same_as not being correct for smallbedroom bed
Nov 28, 2024
cca3047
Add button logic for lights
evavh Nov 29, 2024
ffb2fe2
Add wakeup logic
evavh Nov 29, 2024
7d34931
Fix accidentally blocking sleeps
evavh Nov 30, 2024
5bc814c
Change chrono and time to jiff in brain (untested)
evavh Nov 30, 2024
ab59ccc
Rename alarm.. to job.., move to_datetime out of wakeup
evavh Dec 1, 2024
a41cce8
Renames in jobs
evavh Dec 1, 2024
d4bbeb1
Small rearrangements, yagni and less pub
evavh Dec 1, 2024
2e4ed7f
Move wakeup mod to large_bedroom
evavh Dec 1, 2024
2c2406d
Fix critical time zone crash on startup
evavh Dec 1, 2024
eb2ab82
Add wakeup to small bedroom (only once)
evavh Dec 1, 2024
8434132
move remaining lamps to zigbee_bridge
Dec 3, 2024
8dc8a91
Merge branch 'main' of github.com:dvdsk/HomeAutomation
Dec 3, 2024
d4e7aa7
removes now unused hue bridge light system
Dec 3, 2024
187d13a
Overhaul structure SB, switch to K and normalized bri
evavh Dec 4, 2024
d64d5a2
Make wakeup length setting
evavh Dec 4, 2024
6c8327c
Turn kitchen lights off when SB sleep
evavh Dec 4, 2024
2fdc28d
Turn kitchen lights off when SB sleep
evavh Dec 4, 2024
148bdd8
Add tracing for wakeup
evavh Dec 5, 2024
0bcd9ad
Add every day option to Job
evavh Dec 5, 2024
07f6201
Remove old wakeup and port jobs to dbstruct, untested
evavh Dec 7, 2024
3fc2066
Don't add jobs that already exist
evavh Dec 7, 2024
101b80f
Set wakeup SB to repeat every day
evavh Dec 7, 2024
a551e8d
Merge payloads for hue lights
evavh Dec 7, 2024
3a60580
Fix critical crash in brain
evavh Dec 7, 2024
e7d016b
Fix hue issues by collecting changes before sending
evavh Dec 7, 2024
e5a683c
Remove dbg statements
evavh Dec 7, 2024
f318618
moved sensors retry/reinit + driver trait to seperate crate
Dec 7, 2024
597a298
Merge branch 'main' of github.com:dvdsk/HomeAutomation
Dec 7, 2024
0b72b37
nodes no long depend on sensor driver crates
Dec 7, 2024
0c579c9
Rename datetime fn and remove unused time crate
evavh Dec 9, 2024
2651f40
Add nightlight
evavh Dec 9, 2024
2153269
Add logging to job event and repeat
evavh Dec 9, 2024
0983086
Update test script
evavh Dec 10, 2024
527ab71
Add thorough debugging code
evavh Dec 10, 2024
0f17f8b
Fix event timer not running and job list deadlock
evavh Dec 10, 2024
3fc8547
Fix wakeup logic
evavh Dec 11, 2024
9e7cc08
Add mqtt ip cli parameter for testing
evavh Dec 11, 2024
7153120
ported bed-lb node to new sensors crate
Dec 11, 2024
c76f7b5
Merge branch 'main' of github.com:dvdsk/HomeAutomation
Dec 11, 2024
9a0b433
Rewrite lights system to use new Device trait
evavh Dec 11, 2024
9cf43c1
Move contents of lights mod to lib to reduce nesting
evavh Dec 11, 2024
a020700
Rename light to device where appropriate
evavh Dec 11, 2024
eaf3b95
Rewrite everything to use Property
evavh Dec 12, 2024
8aa48fc
Add radiator, mostly tested and working
evavh Dec 14, 2024
144c030
Fix brain to work with new zigbee bridge structure
evavh Dec 14, 2024
a31e896
Add fn to remove old jobs for a certain event
evavh Dec 14, 2024
ea41cc7
Tweak SB wakeup
evavh Dec 14, 2024
7addcae
refactor&fix zigbee-bridge + adds radiator bridge
Dec 23, 2024
73cc99b
Merge branch 'main' of github.com:dvdsk/HomeAutomation
Dec 23, 2024
462fff6
Fix? Ikea lights only partially responding
evavh Dec 23, 2024
2c0ef0d
Fix? conflicts between zigbee-bridge instances
evavh Dec 23, 2024
b28bee2
Fix radiator parsing and color eyre logging
evavh Dec 24, 2024
d960441
Change small bedroom and kitchen light behavior
evavh Dec 24, 2024
f245901
expand byteseries error handling in data-store
Dec 25, 2024
7d8011e
update byteseries (critical bug fix)
Dec 25, 2024
5abfe8a
Increase send delay to hopefully fix Ikea issues
evavh Dec 26, 2024
b5ab63f
Merge branch 'master'
Dec 26, 2024
7d9040f
add radiator to protocol + add callback to get radiator to zigbee bri…
Dec 26, 2024
3dc7c39
fix errors caused by moving is_same_as to trait
Dec 26, 2024
aea4fa3
doc is_same_as + set temp_res for radiator
Dec 26, 2024
ddd5c53
send readings from mqtt to data-server
Dec 26, 2024
3d6db11
fixes bug where cancelling SubscribedClient::next leads to reconnect
Dec 26, 2024
dbd66ed
fixes always reconnecting post cancel of SubscribedClient::next
Dec 26, 2024
d7d804b
queued items (mpsc) are only send if within temporal resolution
Dec 26, 2024
7938a40
Merge branch 'main' of github.com:dvdsk/HomeAutomation
Dec 26, 2024
a92a002
removes leftover dbg
Dec 26, 2024
e29f013
data-source api client tries resend on error up to send deadline
Dec 26, 2024
0325d13
update byteseries dep
Dec 27, 2024
c8a5487
add profiling setup for radiator-bridge
Dec 27, 2024
9203076
use source for error chain instead of formatting in msg
Dec 27, 2024
79a4050
add journalctl fields example to docs
Dec 28, 2024
010a05c
fix data_sources not reconnecting but reporting erros forever
Dec 28, 2024
d65e0ad
fix crash if report did not contain backtrace
Dec 28, 2024
84500e3
refactor
Dec 28, 2024
925aa85
remove some unneeded log statements lowerd level of others
Dec 28, 2024
ebd59aa
fixes div by zero due to min_sample_interval being zero
Dec 28, 2024
cb8e482
add profile setup for brain, fix that of radiator-bridge
Dec 29, 2024
c3ccc3b
update deps + remove unused deps
Dec 29, 2024
2102f26
fixes test
Dec 29, 2024
fcbb96b
add support for ikea symphonisk panel in small bedroom
Dec 29, 2024
59f3648
fixes ikea symphonisk support
Dec 30, 2024
a945ee6
fix symphonisk (do subscribe) + minor refactor
Dec 30, 2024
77a7162
Rename light_new in system to zigbee
evavh Dec 30, 2024
b52f962
Add radiator setpoint control to small bedroom
evavh Dec 30, 2024
f386aae
fix reset cooldown + update embassy
Dec 31, 2024
258d099
Merge branch 'main' of github.com:dvdsk/HomeAutomation
Dec 31, 2024
7725c7b
Add light functionality to portable buttons
evavh Dec 30, 2024
f39b21e
Fix portablebuttons by adding to filter
evavh Dec 31, 2024
472c276
Add SetBy to radiator readings
evavh Dec 31, 2024
bed8ada
Fix radiator set method parsing
evavh Jan 2, 2025
2a285ac
Add radiator manual override logic and debug
evavh Jan 2, 2025
8095bde
remove dbg! in radbridge
Jan 2, 2025
eb862e8
fix missing affected_readings entry + improve error
Jan 2, 2025
432f26c
Tweak SB radiator values
evavh Jan 4, 2025
1fa9004
adds watchdog to bed-lb + flush network
Jan 2, 2025
718da75
reset node on repeated conn loss
Jan 10, 2025
feb2752
add radiator Setpoint to reading
Jan 10, 2025
df6c8ff
rename sensor-tui -> ui
Jan 11, 2025
4ad9cc0
tests compile again
Jan 11, 2025
d37b4ce
fixes tests
Jan 11, 2025
ae00ea1
update ui deps
Jan 11, 2025
4a68b3a
implements label formatter for radiator and buttons + refactor protocol
Jan 11, 2025
ddfd837
formatter implemented for button
Jan 13, 2025
86bdaa8
push missing files
Jan 13, 2025
7bf6b31
Tweak lamp and radiator timings SB
evavh Jan 13, 2025
ca61fc7
Add interpolation for color correction
evavh Jan 14, 2025
f76f177
Extract module color_correction
evavh Jan 14, 2025
4ddaf49
Complete color correction data
evavh Jan 14, 2025
8cac4e9
Fix color correction
evavh Jan 14, 2025
8a3cefa
Refactor daylight and temp for SB, tweak values
evavh Jan 16, 2025
81ef0c2
Turn hallway lamp auto on and off
evavh Jan 16, 2025
b5f5ffb
hotfix: lamp color time swapped
Jan 16, 2025
047b32a
text-widget can handle multiple readings
Jan 17, 2025
ae56980
adds units to json format, fixes json format
Jan 17, 2025
ab1b090
make it possible to clear resolve cache (re setup)
Jan 17, 2025
6a447b9
Hotfix the hotfix
evavh Jan 17, 2025
b4a34cf
add export and import command to data-store
Jan 18, 2025
2604f18
move data from server/db to own root mod
Jan 18, 2025
c418768
fix warnings
Jan 18, 2025
8eed211
Merge branch 'main' of github.com:dvdsk/HomeAutomation
Jan 18, 2025
2299b4c
adds export functionality, writes csv
Jan 18, 2025
e1aa260
add extensive description to bitspec::encode function
Jan 19, 2025
20c12c8
Tweak heating and wakeup SB
evavh Jan 23, 2025
62ecd48
Add tcp control of air filtration box
evavh Jan 23, 2025
7d5a480
Add pm2_5 logic to air filtration SB
evavh Jan 25, 2025
58a98e4
Move air filtration logic together
evavh Jan 25, 2025
d26ca5b
Tweak SB values
evavh Feb 1, 2025
3a4c44c
disable misbehaving radiator control + add logging to rad contrl
Feb 2, 2025
5f85a9e
Fix text-widget not compiling because of clap arg
evavh Feb 4, 2025
67775e5
Fix parse error for portable button panel
evavh Feb 4, 2025
baa8411
Disable radiator override and re-enable setting
evavh Feb 4, 2025
08032af
Fix log errors originating from portable buttons
evavh Feb 6, 2025
4fa09f9
Fix another portable button error
evavh Feb 7, 2025
5ae6fc7
Send all z2m set commands twice
evavh Feb 11, 2025
859d3af
piano lamp replaced with tradfri
Feb 14, 2025
f923a42
Merge branch 'main' of github.com:dvdsk/HomeAutomation
Feb 14, 2025
5bce0bf
Add info to error
evavh Feb 15, 2025
c6f449e
Add wakeup override to SB
evavh Feb 17, 2025
030feee
Add simple daylight behaviour room for entrance
evavh Feb 17, 2025
793392b
Update lamp models
evavh Feb 17, 2025
22347a2
Add Sleep behaviour to entrance
evavh Feb 20, 2025
8ebd24a
Tweak lights and SB temperature
evavh Feb 28, 2025
6f24776
Tweak airbox speed and decouple from LB sensor
evavh Mar 8, 2025
c14de31
Add 1h delay to wakeup on Sunday
evavh Mar 8, 2025
ee8e7e7
Merge branch 'main' of github.com:dvdsk/HomeAutomation
Mar 17, 2025
134a946
better docs / refactor (broken)
Feb 14, 2025
63c4692
renames, better export error handling
Feb 19, 2025
95a0c4a
adds test script for reproducing bug
Feb 19, 2025
572d462
fixes compression algorithm for lengths < 8bits
Mar 5, 2025
97545ab
adds import command
Mar 17, 2025
1e3a6af
fix typos
Mar 17, 2025
cd46616
script to update data
Mar 17, 2025
d6e5e56
switch to latest upstream byteseries
Mar 17, 2025
9f4aff2
fix import not zero-ing line
Mar 18, 2025
8a8f469
add import/export test
Mar 18, 2025
105f722
rename sensor-nodes -> nodes
Mar 18, 2025
aabcdde
adds Airbox to protocol
Mar 18, 2025
2796c05
reorder nodes into embassy and esp32
Mar 19, 2025
754d19b
adds airbox firmware
Mar 19, 2025
43774ce
fix esp main setup
Mar 19, 2025
3e65c7c
fix broken is_same_as for airbox
Mar 19, 2025
5d4dd21
fixes to fan button
Mar 20, 2025
c657bf2
update embassy to latest version
Mar 20, 2025
fd6ce40
refactors bed-lb to use more tasks instead of select
Mar 23, 2025
e861b49
fix log store returning error if range is past last error
Mar 23, 2025
559aa23
ui error reports no longer cutting off location, no longer printing e…
Mar 23, 2025
3e69ca0
extracts usb logic to its own lib
Mar 26, 2025
f31fb29
fix button panel name
Mar 26, 2025
90495d2
adds button pannel, port of evavh buttonpanel
Mar 26, 2025
1292355
improved usb bridge error msgs
Mar 26, 2025
a1b9c29
replaces config function with macro
Mar 26, 2025
c2642a5
deploys to second pi
Mar 26, 2025
070c903
Track Cargo.lock
evavh Mar 27, 2025
9b23fc0
Move small bedroom audio controls into brain
evavh Mar 27, 2025
0bbef9e
switch to local embassy for debugging
Mar 27, 2025
1a7be72
Merge branch 'main' of github.com:dvdsk/HomeAutomation
Mar 28, 2025
44c2b7d
switch data range from Range to RangeInclusive
Jan 18, 2025
6f0930e
Add meditation controls to portable button panels
evavh Mar 28, 2025
1e5d6c8
update script now prompts user to make protocol change
Mar 28, 2025
308abae
Merge branch 'main' of github.com:dvdsk/HomeAutomation
Mar 28, 2025
1bb98e8
Add volume setting per mode
evavh Mar 28, 2025
d2cffdf
refactors update script
Mar 28, 2025
c4a0a6a
Merge branch 'protocol-inclusiverange'
Mar 28, 2025
f637f12
make airbox use rangeinclusive
Mar 28, 2025
aa7899a
Merge branch 'main' of github.com:dvdsk/HomeAutomation
Mar 28, 2025
66f7d1f
update to avoid unmaintained users carte
Mar 28, 2025
1dcd616
Updates dependencies
Mar 29, 2025
d26755f
Remove confusing defaults for audio modes
evavh Mar 31, 2025
aff76dc
Make meditation mode dependent on time
evavh Apr 3, 2025
efc36f5
Add kitchen to small bedroom override button
evavh Apr 3, 2025
6619329
remove error reporting for parsing (see comment)
Apr 7, 2025
7d6b012
Merge branch 'main' of github.com:dvdsk/HomeAutomation
Apr 7, 2025
578484c
Bump crossbeam-channel from 0.5.14 to 0.5.15
dependabot[bot] Apr 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ __pycache__
debugToRemoteHost.sh
hueBridgeLogin
keys/
data/
releaseToRemoteHost.sh
specs/
userdb.hm

# Rust #
#####################
target/
src/input/web_api/logins.rs
database/
4,768 changes: 2,988 additions & 1,780 deletions Cargo.lock

Large diffs are not rendered by default.

72 changes: 43 additions & 29 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,34 +1,48 @@
[package]
name = "HomeAutomation"
version = "0.1.0"
authors = ["David Kleingeld <dskleingeld@gmail.com>"]
edition = "2018"
[workspace]
resolver = "2"
members = ["crates/*"]
exclude = ["nodes/embassy/bed-lb", "nodes/embassy/bed-sb",
"nodes/esp32/airbox"]

[dependencies]
actix-web = { version = "0.7.15", features = ["rust-tls"] }
actix-web-httpauth = "0.1.0"
actix = "0.7.5"
serde = "1.0"
serde_yaml = "0.8"
log = "0.4"
[workspace.dependencies]
data-server = { path = "crates/data-server" }
data-store = { path = "crates/data-store" }
log-store = { path = "crates/log-store" }
protocol = { path = "crates/protocol" }
zigbee-bridge = { path = "crates/zigbee-bridge" }
rpc = { path = "crates/rpc" }
logger = { path = "crates/logger" }

#sysfs_gpio = { version = "0.5.3", features = ["use_tokio"] }
sysfs_gpio = { git = "https://github.com/rust-embedded/rust-sysfs-gpio", branch = "master", features = ["use_tokio"] }
byteseries = { git = "https://github.com/dvdsk/byteseries", rev="a9da72e9585e5f5a8cc3cf543d6ca2561ad7007a" }

tokio = "0.1.15"
futures = { version = "0.1"}
serde = { version = "1", features = ["derive"], default-features = false }
tokio = { version = "1.38", features = ["rt-multi-thread"] }
tokio-util = { version = "0.7.13", features = ["codec"] }
itertools = { version = "0.14" }
bincode = { version = "2.0", default-features = false, features = ["serde", "std"] }
gethostname = "0.5"
governor = "0.8"
color-eyre = "0.6.3"
tracing = "0.1.40"
tracing-error = "0.2"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
futures = "0.3.31"
futures-concurrency = "7.6.2"
jiff = "0.1"
clap = { version = "4", features = ["derive"]}
rand = "0.9"
smallvec = { version = "2.0.0-alpha.11" }
strum = { version = "0.27", features = ["derive"] }
ron = "0.9"
thiserror = "2"
reserve-port = "2.2.0"

#dont forget to run cargo update when these change
philipshue = { git = "https://github.com/dskleingeld/philipshue", branch = "master" }
dataserver = { git = "https://github.com/dskleingeld/dataserver", branch = "as_lib" }
[workspace.package]
rust-version = "1.82"
edition = "2021"
license = "GPLv3"
authors = ["David Kleingeld & Eva van Houten"]

#for local dev purpose we use below targets
#dataserver = { path = "../dataserver"}
#philipshue = { path = "../philipshue"}

linux-embedded-hal = "0.2.2"
bme280 = "0.1.1"

smallvec = "0.6.6"
chrono = { version = "0.4.6", features = ["serde"] }
bytes = "0.4.11"
[profile.release-with-debug]
inherits = "release"
debug = true
2 changes: 2 additions & 0 deletions crates/brain/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.aarch64-unknown-linux-musl]
rustflags = ["-Clinker=rust-lld"]
41 changes: 41 additions & 0 deletions crates/brain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[package]
name = "brain"
version = "0.1.0"
rust-version.workspace = true
edition.workspace = true
license.workspace = true
authors.workspace = true

[dependencies]
protocol = { workspace = true, features = ["alloc"] }
data-server = { workspace = true }
zigbee-bridge = { workspace = true }

futures.workspace = true
tokio = { workspace = true, features = ["full"] }

serde.workspace = true
serde_yaml = "0.9"
bincode.workspace = true

thiserror.workspace = true

jiff = { workspace = true, features = ["serde"] }

bytes = "1.5"
byteorder = "1.4"

sled = "0.34"

mpd = "0.1"
rand.workspace = true

futures-util = "0.3.30"
tracing = {workspace = true}
logger.workspace = true
clap = { workspace = true }
futures-concurrency = { workspace = true }
strum.workspace = true
dbstruct = { git = "https://github.com/dvdsk/dbstruct" }
color-eyre.workspace = true
mpdrs = "0.1.0"
17 changes: 17 additions & 0 deletions crates/brain/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -e

SERVER="sgc" # ssh config name or full address

cargo build --target=aarch64-unknown-linux-musl --release
rsync -vh --progress \
../../target/aarch64-unknown-linux-musl/release/brain \
$SERVER:/tmp/

cmds="
sudo mv /tmp/brain /home/ha/brain
sudo chown ha:ha /home/ha/brain
sudo systemctl restart brain
"

ssh -t $SERVER "$cmds"
10 changes: 10 additions & 0 deletions crates/brain/profile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

cargo build --profile=release-with-debug
echo '1' | sudo tee /proc/sys/kernel/perf_event_paranoid

samply record ../../target/release-with-debug/brain \
--data-server 192.168.1.43:1235 \
--mpd-ip 192.168.1.43 \
--http-port 34326 \
--mqtt-ip 192.168.1.43
5 changes: 5 additions & 0 deletions crates/brain/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[toolchain]
channel = "stable"
components = []
targets = [ "aarch64-unknown-linux-musl" ]
profile = "minimal"
26 changes: 26 additions & 0 deletions crates/brain/src/controller/environment/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/// will store a short history of the last sensor values
/// useful for debouncing events (someone passing in front
/// light sensor vs a cloud)
use protocol::SensorValue;

// struct History<T> {
// last_values: Vec<T>,
// }

pub struct Environment {
// light: History<f32>,
}

impl Environment {
pub fn update(&self, _: SensorValue) {}
}

impl std::default::Default for Environment {
fn default() -> Self {
Environment {
// light: History {
// last_values: Vec::new(),
// },
}
}
}
149 changes: 149 additions & 0 deletions crates/brain/src/controller/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
mod rooms;

use crate::system::System;
pub use protocol::Reading;
use serde::{Deserialize, Serialize};
use tokio::sync::broadcast;
use tokio::task::JoinSet;

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub enum Event {
Sensor(Reading),
WakeupLB,
WakeupSB,
StateChangeSB(rooms::small_bedroom::State),
}

#[derive(Clone)]
pub(crate) struct RestrictedSystem {
allowed_lights: Vec<&'static str>,
allowed_radiators: Vec<&'static str>,
system: System,
}

impl RestrictedSystem {
async fn one_lamp_ct(
&mut self,
name: &'static str,
kelvin: usize,
bri: f64,
) {
if self.allowed_lights.contains(&name) {
self.system.zigbee.set_color_temp(name, kelvin);
self.system.zigbee.set_brightness(name, bri);
}
}

async fn one_lamp_on(&mut self, name: &'static str) {
if self.allowed_lights.contains(&name) {
self.system.zigbee.set_on(name);
}
}

async fn one_lamp_off(&mut self, name: &'static str) {
if self.allowed_lights.contains(&name) {
self.system.zigbee.set_off(name);
}
}

async fn all_lamps_ct(&mut self, kelvin: usize, bri: f64) {
for name in &self.allowed_lights {
self.system.zigbee.set_color_temp(name, kelvin);
self.system.zigbee.set_brightness(name, bri);
}
}

async fn all_lamps_off(&mut self) {
for name in &self.allowed_lights {
self.system.zigbee.set_off(name);
}
}

async fn all_lamps_on(&mut self) {
for name in &self.allowed_lights {
self.system.zigbee.set_on(name);
}
}

async fn all_lamps_but_one_off(&mut self, leave_this_on: &str) {
for name in &self.allowed_lights {
if *name != leave_this_on {
self.system.zigbee.set_off(name);
}
}
}

async fn all_lamps_but_one_on(&mut self, leave_this_off: &str) {
for name in &self.allowed_lights {
if *name != leave_this_off {
self.system.zigbee.set_on(name);
}
}
}

async fn set_radiators_setpoint(&mut self, temperature: f64) {
for name in &self.allowed_radiators {
self.system.zigbee.set_radiator_setpoint(name, temperature);
}
}
}

pub fn start(
subscribed: [broadcast::Receiver<Event>; 4],
sender: broadcast::Sender<Event>,
system: System,
) -> JoinSet<()> {
tracing::info!("starting");
let mut tasks = JoinSet::new();
let [rx1, rx2, rx3, rx4] = subscribed;

let restricted = RestrictedSystem {
system: system.clone(),
allowed_lights: vec![
"large_bedroom:cabinet",
"large_bedroom:ceiling",
"large_bedroom:desk",
"large_bedroom:wardrobe",
"large_bedroom:bed",
],
allowed_radiators: vec!["large_bedroom:radiator"],
};
tasks.spawn(rooms::large_bedroom::run(rx1, sender.clone(), restricted));

let restricted = RestrictedSystem {
system: system.clone(),
allowed_lights: vec![
"small_bedroom:ceiling",
"small_bedroom:bureau",
"small_bedroom:piano",
],
allowed_radiators: vec!["small_bedroom:radiator"],
};
tasks.spawn(rooms::small_bedroom::run(rx2, sender.clone(), restricted));

let restricted = RestrictedSystem {
system: system.clone(),
allowed_lights: vec![
"kitchen:ceiling",
"kitchen:hood_left",
"kitchen:hood_right",
"kitchen:fridge",
"kitchen:hallway",
],
allowed_radiators: vec![],
};
tasks.spawn(rooms::kitchen::run(rx3, sender.clone(), restricted));

let restricted = RestrictedSystem {
system: system.clone(),
allowed_lights: vec![
"hallway:ceiling",
"bathroom:ceiling",
"toilet:ceiling",
],
allowed_radiators: vec![],
};
tasks.spawn(rooms::entrance::run(rx4, sender, restricted));

tasks
}
4 changes: 4 additions & 0 deletions crates/brain/src/controller/rooms.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod large_bedroom;
pub mod small_bedroom;
pub mod kitchen;
pub mod entrance;
Loading