Skip to content

Commit

Permalink
Add example of how to pass command line args (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
th3w1zard1 authored and basnijholt committed Mar 27, 2023
1 parent 0127496 commit 6974e9c
Show file tree
Hide file tree
Showing 5 changed files with 366 additions and 23 deletions.
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ adaptive_lighting:
| `lights` | yes | entity_id(s) of lights, if not specified, all lights in the switch are selected. |
| `manual_control` | yes | Whether to add ('true') or remove ('false') the light from the 'manual_control' list, default: true |

`adaptive_lighting.change_switch_settings` (new in 1.7.0) Change any of the above configuration options of Adaptive Lighting (such as `sunrise_time` or `prefer_rgb_color`) with a service call directly from your script/automation.

| DISALLOWED service data | Description |
| ------------------------- | --------------------------------------------------------------------------------------------------- |
| `entity_id` | You cannot change the switch's unique_id, it's already been registered |
| `lights` | See above, you may call adaptive_lighting.apply() with your lights or create a new config instead |
| `name` | See above. You can already rename your switch's display name in Home Assistant's UI. |
| `interval` | Nope. The interval is only used once when the config loads. A config change and restart is required |

## Automation examples

Expand Down Expand Up @@ -172,6 +180,53 @@ Toggle multiple Adaptive Lighting switches to "sleep mode" using an `input_boole
- switch.adaptive_lighting_sleep_mode_bedroom
```

Set your sunrise and sunset time based on your alarm. The below script sets sunset_time exactly 12 hours after the custom sunrise time.

```
iphone_carly_wakeup:
alias: iPhone Carly Wakeup
sequence:
- condition: state
entity_id: input_boolean.carly_iphone_wakeup
state: 'off'
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.carly_iphone_wakeup
data:
time: '{{ now().strftime("%H:%M:%S") }}'
- service: input_boolean.turn_on
target:
entity_id: input_boolean.carly_iphone_wakeup
- repeat:
count: '{{ (states.switch | map(attribute=''entity_id'') | select(">","switch.adaptive_lighting_al_") |
select("<", "switch.adaptive_lighting_al_z") | join(",")).split(",")|length
}}'
sequence:
- service: adaptive_lighting.change_switch_settings
data:
entity_id: switch.adaptive_lighting_al_den_ceilingfan_lights
sunrise_time: '{{ now().strftime("%H:%M:%S") }}'
sunset_time: '{{ (as_timestamp(now()) + 12*60*60) | timestamp_custom("%H:%M:%S")
}}'
- service: script.turn_on
target:
entity_id: script.run_wakeup_routine
- service: input_boolean.turn_off
target:
entity_id:
- input_boolean.carly_iphone_winddown
- input_boolean.carly_iphone_bedtime
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.wakeup_time
data:
time: '{{ now().strftime("%H:%M:%S") }}'
- service: script.adaptive_lighting_disable_sleep_mode
mode: queued
icon: mdi:weather-sunset
max: 10
```
# Other
See the documentation of the PR at https://deploy-preview-14877--home-assistant-docs.netlify.app/integrations/adaptive_lighting/ and [this video on Reddit](https://www.reddit.com/r/homeassistant/comments/jabhso/ha_has_it_before_apple_has_even_finished_it_i/) to see how to add the integration and set the options.
Expand Down
3 changes: 3 additions & 0 deletions custom_components/adaptive_lighting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ async def async_setup(hass: HomeAssistant, config: dict[str, Any]):
# This will reload any changes the user made to any YAML configurations.
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)

# quickly populate data for change_switch_settings before actually loading integration.
# update_services_yaml()

if DOMAIN in config:
for entry in config[DOMAIN]:
hass.async_create_task(
Expand Down
2 changes: 2 additions & 0 deletions custom_components/adaptive_lighting/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
CONF_MANUAL_CONTROL = "manual_control"
SERVICE_APPLY = "apply"
CONF_TURN_ON_LIGHTS = "turn_on_lights"
SERVICE_CHANGE_SWITCH_SETTINGS = "change_switch_settings"
CONF_USE_DEFAULTS = "use_defaults"

CONF_ADAPT_DELAY, DEFAULT_ADAPT_DELAY = "adapt_delay", 0
TURNING_OFF_DELAY = 5
Expand Down
178 changes: 178 additions & 0 deletions custom_components/adaptive_lighting/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ apply:
example: false
selector:
boolean:

set_manual_control:
description: Mark whether a light is 'manually controlled'.
fields:
Expand All @@ -65,3 +66,180 @@ set_manual_control:
default: true
selector:
boolean:

change_switch_settings:
description: "Change any settings you'd like in the switch. All options here are the same as in the config flow."
fields:
entity_id:
description: "entity_id of the Adaptive Lighting switch."
required: true
selector:
entity:
domain: switch
use_defaults:
description: "(default: 'current' for current settings) You can set this to 'factory', 'configuration', or 'current' to reset the variables not being set with this service call. 'current' leaves them as is, 'configuration' resets to whatever already initializes at startup, 'factory' resets to the default values listed in the documentation."
example: "current"
required: false
default: "current"
selector:
select:
options:
- "current"
- "configuration"
- "factory"
turn_on_lights:
description: "Turn on the lights that are off, default: false"
example: false
required: false
selector:
boolean:
initial_transition:
description: "initial_transition: When lights turn 'off' to 'on'. (seconds)"
example: 1
required: false
selector:
text:
sleep_transition:
description: "sleep_transition: When 'sleep_state' changes. (seconds)"
example: 1
required: false
selector:
text:
max_brightness:
description: "max_brightness: Highest brightness of lights during a cycle. (%)"
required: false
example: 100
selector:
text:
max_color_temp:
description: "max_color_temp: Coldest hue of the color temperature cycle. (Kelvin)"
required: false
example: 5500
selector:
text:
min_brightness:
description: "min_brightness: Lowest brightness of lights during a cycle. (%)"
required: false
example: 1
selector:
text:
min_color_temp:
description: "min_color_temp, Warmest hue of the color temperature cycle. (Kelvin)"
required: false
example: 2000
selector:
text:
only_once:
description: "only_once: Only adapt the lights when turning them on."
example: false
required: false
selector:
boolean:
prefer_rgb_color:
description: "prefer_rgb_color: Use 'rgb_color' rather than 'color_temp' when possible."
required: false
example: false
selector:
boolean:
separate_turn_on_commands:
description: "separate_turn_on_commands: Separate the commands for each attribute (color, brightness, etc.) in 'light.turn_on' (required for some lights)."
required: false
example: false
selector:
boolean:
send_split_delay:
description: "send_split_delay: wait between commands (milliseconds), when separate_turn_on_commands is used. May ensure that both commands are handled by the bulb correctly."
required: false
example: 0
selector:
boolean:
sleep_brightness:
description: "sleep_brightness, Brightness setting for Sleep Mode. (%)"
required: false
example: 1
selector:
text:
sleep_rgb_or_color_temp:
description: "sleep_rgb_or_color_temp, use 'rgb_color' or 'color_temp'"
required: false
example: "color_temp"
selector:
select:
options:
- "rgb_color"
- "color_temp"
sleep_rgb_color:
description: "sleep_rgb_color, in RGB"
required: false
selector:
color_rgb:
sleep_color_temp:
description: "sleep_color_temp: Color temperature setting for Sleep Mode. (Kelvin)"
required: false
example: 1000
selector:
text:
sunrise_offset:
description: sunrise_offset, in +/- seconds (integer)
required: false
example: 0
selector:
number:
min: 0
max: 86300
sunrise_time:
description: sunrise_time, in 'HH:MM:SS' format (if 'None', it uses the actual sunrise time at your location)
required: false
example: ""
selector:
time:
sunset_offset:
description: sunset_offset, in +/- seconds (integer)
required: false
example: ""
selector:
number:
min: 0
max: 86300
sunset_time:
description: sunset_time, in 'HH:MM:SS' format (if 'None', it uses the actual sunset time at your location)
example: ""
required: false
selector:
time:
max_sunrise_time:
description: "max_sunrise_time: Manual override of the maximum sunrise time, if 'None', it uses the actual sunrise time at your location (HH:MM:SS)"
example: ""
required: false
selector:
time:
min_sunset_time:
description: "min_sunset_time: Manual override of the minimum sunset time, if 'None', it uses the actual sunset time at your location (HH:MM:SS)"
example: ""
required: false
selector:
time:
take_over_control:
description: "take_over_control: If anything but Adaptive Lighting calls 'light.turn_on' when a light is already on, stop adapting that light until it (or the switch) toggles off -> on."
required: false
example: true
selector:
boolean:
detect_non_ha_changes:
description: "detect_non_ha_changes: detects all >10% changes made to the lights (also outside of HA), requires 'take_over_control' to be enabled (calls 'homeassistant.update_entity' every 'interval'!)"
required: false
example: false
selector:
boolean:
transition:
description: "Transition time when applying a change to the lights (seconds)"
required: false
example: 45
selector:
text:
adapt_delay:
description: "adapt_delay: wait time between light turn on (seconds), and Adaptive Lights applying changes to the light state. May avoid flickering."
required: false
example: 0
selector:
text:
Loading

0 comments on commit 6974e9c

Please sign in to comment.