mirror of
				https://github.com/CCOSTAN/Home-AssistantConfig.git
				synced 2025-10-31 10:46:20 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			61 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			YAML
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			YAML
		
	
	
		
			Executable File
		
	
	
	
	
| ##############################################################################
 | |
| ###  Detect when lights are turned on and adjust them accordingly based on time.
 | |
| ###  Code by @JesseWebDotCom
 | |
| ## @CCOSTAN
 | |
| ## Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
 | |
| ##############################################################################
 | |
| - alias: detect lights and adjust the brightness when turned on based on time
 | |
|   id: 844b6be0-3ba3-4f8a-bbcd-a5ec5abdb88a
 | |
|   mode: parallel
 | |
|   trigger:
 | |
|     - platform: event
 | |
|       event_type: state_changed
 | |
| 
 | |
|   condition:
 | |
|     - condition: state
 | |
|       entity_id: group.family
 | |
|       state: 'home'
 | |
|     - condition: state
 | |
|       entity_id: input_boolean.alert_mode
 | |
|       state: 'off'
 | |
|     - condition: template
 | |
|       value_template: "{{ trigger.event.data is not none }}"
 | |
|     - condition: template
 | |
|       value_template: "{{ trigger.event.data.entity_id is not none }}"
 | |
|     - condition: template
 | |
|       value_template: "{{ trigger.event.data.entity_id.split('.')[0] == 'light' }}"
 | |
|     # - condition: template
 | |
|     #   value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.tv' }}"
 | |
|     - condition: template
 | |
|       value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.couch' }}"
 | |
|     - condition: template
 | |
|       value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.office' }}"
 | |
|     - condition: template
 | |
|       value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.flood_2' }}"
 | |
|     - condition: template
 | |
|       value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.treeflood' }}"
 | |
|     # - condition: template
 | |
|     #   value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.led' }}"
 | |
|     - condition: template
 | |
|       value_template: "{{ trigger.event.data.entity_id.split('_')[1] != 'screensaver' }}"
 | |
|     - condition: template
 | |
|       value_template: "{{ trigger.event.data.new_state.state == 'on' }}"
 | |
|     - condition: template
 | |
|       value_template: "{{ trigger.event.data.old_state.state == 'off' }}"
 | |
| 
 | |
|   action:
 | |
|     - service: light.turn_on
 | |
|       data:
 | |
|         entity_id: "{{ trigger.event.data.entity_id }}"
 | |
|         brightness: >
 | |
|           {% set hour=states("sensor.time").split(':')[0] | int %}
 | |
|           {%- if hour >= 5 and hour < 8  -%}
 | |
|             50
 | |
|           {%- elif hour >= 8 and hour <20  -%}
 | |
|             255
 | |
|           {%- elif hour >= 20 and hour <24  -%}
 | |
|             40
 | |
|           {%- else -%}
 | |
|             15
 | |
|           {%- endif %}
 |