-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
117 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ export { | |
watchPausable, | ||
} from "npm:@vueuse/[email protected]"; | ||
|
||
export { watch } from "npm:@vue/[email protected]"; | ||
export { watch, nextTick } from "npm:@vue/[email protected]"; | ||
|
||
export { config as dotenvConfig } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useState, computed } from "../mod.ts"; | ||
|
||
/** | ||
* | ||
* @param entity Entity id | ||
* @returns Computed lumen float value | ||
*/ | ||
export function useLumen(entity: string) { | ||
const state = useState(entity); | ||
|
||
return computed(() => { | ||
if (!state.value) { | ||
return null; | ||
} | ||
return parseFloat(state.value.state); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { | ||
computed, | ||
useBrightness, | ||
useAsyncState, | ||
useNewBoolean, | ||
useNewLight, | ||
useLightMapping, | ||
watch, | ||
} from "../mod.ts"; | ||
import { useLumen } from "./lx.ts"; | ||
|
||
const sunState = await useAsyncState("sun.sun"); | ||
|
||
const motion1 = await useAsyncState( | ||
"binary_sensor.0x00124b0025091116_occupancy" | ||
); | ||
const motion2 = await useAsyncState( | ||
"binary_sensor.0x00124b0025090f28_occupancy" | ||
); | ||
|
||
const lx = useLumen("sensor.0xe0798dfffebf23d7_illuminance_lux"); | ||
|
||
const lightState = await useAsyncState("light.flur_deckenlicht"); | ||
|
||
const state = useNewLight(lightState, true); | ||
|
||
const lightShouldBeOn = computed(() => { | ||
// Sun is above horizon, no light needed | ||
if (sunState.value.state === "above_horizon") { | ||
if (!lx.value || !state.value || lx.value > 22) { | ||
if (!state.value) { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
return motion1.value?.state === "on" || motion2.value?.state === "on"; | ||
}); | ||
|
||
watch( | ||
lightShouldBeOn, | ||
(lightShouldBeOn) => { | ||
console.log({ lightShouldBeOn }); | ||
}, | ||
{ immediate: true } | ||
); | ||
|
||
const brightness = useBrightness({ | ||
maxBrigthness: 140, | ||
}); | ||
|
||
useLightMapping({ | ||
entity: state, | ||
expectedValue: lightShouldBeOn, | ||
expectedBrightness: brightness, | ||
isDisabled: useNewBoolean( | ||
await useAsyncState("input_boolean.flur_disableauto_state"), | ||
true | ||
), | ||
isDisabledBrightness: useNewBoolean( | ||
await useAsyncState("input_boolean.flur_disableauto_brightness"), | ||
true | ||
), | ||
autoEnableTime: await useAsyncState("input_text.flur_disableauto_state_time"), | ||
autoEnableTimeBrightness: await useAsyncState( | ||
"input_text.flur_disableauto_brightness_time" | ||
), | ||
debug: true, | ||
}); |