Parcourir la source

Commit many changes from last christmas

pi il y a 3 ans
Parent
commit
b634c11c4f
9 fichiers modifiés avec 93 ajouts et 32 suppressions
  1. 2 0
      .gitignore
  2. 9 4
      configuration.yaml
  3. 10 1
      input_booleans.yaml
  4. 10 0
      input_numbers.yaml
  5. 6 2
      lights.yaml
  6. 24 7
      pyscript/bedroom.py
  7. 5 2
      pyscript/home_automations.py
  8. 18 16
      pyscript/state_goto.py
  9. 9 0
      sensors.yaml

+ 2 - 0
.gitignore

@@ -6,6 +6,8 @@
 
 ._.DS_Store
 /custom_components/
+._*.yaml
+
 
 # Logs
 logs

+ 9 - 4
configuration.yaml

@@ -5,7 +5,6 @@ counter:
 logbook:
 notify:
 input_datetime:
-input_number:
 input_select:
 input_text:
 timer:
@@ -14,11 +13,15 @@ recorder:
   db_url: mysql://hassio:hassiopassword@192.168.1.110/hass?charset=utf8
 logger:
   default: info
-  logs:
-    rflink: debug
+#  logs:
+#    rflink: debug
 #    homeassistant.components.rflink: debug
 history:
 
+mqtt:
+  broker: hagaholm.ddns.net
+  port: 1883
+
 pyscript:
   allow_all_imports: true
 
@@ -34,8 +37,9 @@ binary_sensor:
    - platform: rflink
      devices:
        newkaku_02ddc7fa_4:
-         name: Bedroom door
+         name: Bedroom door raw sensor
          device_class: door
+         force_update: true
 
    - platform: workday
      country: SE
@@ -47,6 +51,7 @@ tts:
 
 switch: !include switches.yaml
 input_boolean: !include input_booleans.yaml
+input_number: !include input_numbers.yaml
 sensor: !include sensors.yaml
 light: !include lights.yaml
 group: !include groups.yaml

+ 10 - 1
input_booleans.yaml

@@ -6,4 +6,13 @@ exterior_lights_wanted_state:
 
 movie_mode:
   name: Movie mode
-  icon: mdi:movie
+  icon: mdi:movie
+
+auto_lights_off:
+  name: Auto Lights Off
+  initial: false
+  icon: mdi:weather-sunny
+
+bedroom_door:
+  name: Bedroom door state
+  icon: mdi:door

+ 10 - 0
input_numbers.yaml

@@ -0,0 +1,10 @@
+auto_light_off_lux_value:
+  name: Auto light off lux value
+  initial: 1000
+  min: 200
+  max: 3000
+  step: 50
+  mode: slider
+  unit_of_measurement: lux
+  icon: mdi:weather-sunny
+

+ 6 - 2
lights.yaml

@@ -1,6 +1,8 @@
 
 
 - platform: rflink
+  device_defaults:
+    signal_repetitions: 1
   automatic_add: true
   devices:
 
@@ -34,9 +36,11 @@
     
     newkaku_001ab10a_1:           # Dimmer CMR-101
       name: Liv_room_table_lamp
-      type: switchable
+      type: dimmable
+      signal_repetitions: 1
     newkaku_001ab10a_2:           # Dimmer MWMR-251
       name: Liv_room_corner_lamp
-      type: switchable
+      type: dimmable
+      signal_repetitions: 1
 
 

+ 24 - 7
pyscript/bedroom.py

@@ -1,22 +1,39 @@
 
 
+from homeassistant.const import EVENT_STATE_CHANGED
 
+# This script reacts to the actual sensor on the door
+# It sets the input_boolean which keeps its state during restarts
+# Arguments could be: (entity_id=None, new_state=None, old_state=None):
+@event_trigger(EVENT_STATE_CHANGED, "entity_id=='binary_sensor.bedroom_door_raw_sensor'")
+def bedroom_door_raw_sensor():
+    #log.info(f"monitor_bedroom_door_event: entity {entity_id} changed from {old_state} to {new_state}")
+    log.info(f"********* BEDROOM RAW SENSOR: "+binary_sensor.bedroom_door_raw_sensor+" ***********")
+    input_boolean.bedroom_door = binary_sensor.bedroom_door_raw_sensor
+    pyscript.handle_bedroom_light()
 
 
+
+# This service handles the window light in the bedroom
+# It reacts when the door opens/closes or when a state_goto-script is run
+#    when someone has pressed a button on the wall or kitchen IPhone.
 @service
 def handle_bedroom_light():
     task.unique('handle_bedroom_light')
-    log.info(f"********* BEDROOM LIGHT CONTROL **** Btn_4:" + light.main_button_4 + " Door:"+ binary_sensor.bedroom_door)
+    log.info(f"********* BEDROOM LIGHT CONTROL **** Btn_4:" + light.main_button_4 + " Door:"+ input_boolean.bedroom_door)
     task.sleep(1)
-    if light.main_button_4 == 'on' and binary_sensor.bedroom_door == 'on':
+    if light.main_button_4 == 'on' and input_boolean.bedroom_door == 'on':
         # If OPEN
         switch.turn_on(entity_id='switch.tradfri_outlet')
     else:
         switch.turn_off(entity_id='switch.tradfri_outlet')
 
 
-@state_trigger("binary_sensor.bedroom_door")
-def bedroom_door_sensor():
-    task.unique('bedroom_door_sensor')
-    log.info(f"********* BEDROOM DOOR: "+binary_sensor.bedroom_door+" ***********")
-    pyscript.handle_bedroom_light()
+"""
+# This way does not work, beacuse it does not react to "off" when the door is already "off/aka Unknown" after a restart of HA
+@state_trigger("binary_sensor.bedroom_door_raw_sensor")
+def bedroom_door_raw_sensor():
+    log.info(f"********* BEDROOM RAW SENSOR: "+binary_sensor.bedroom_door_raw_sensor+" ***********")
+    input_boolean.bedroom_door = binary_sensor.bedroom_door_raw_sensor
+    pyscript.handle_bedroom_light()
+"""

+ 5 - 2
pyscript/home_automations.py

@@ -3,17 +3,20 @@
 state.persist('pyscript.home_auto_lights_off_has_been_night','false')
 
 
-@state_trigger("int(sensor.lux_outside_the_garage) > 1000", state_hold_false=0)
+@state_trigger("int(sensor.lux_outside_the_garage) > int(float(input_number.auto_light_off_lux_value))", state_hold_false=0)
 def automate_home_auto_lights_off():
+    log.info(f"********* AUTO LIGHTS OFF *********** Lux: " + str(sensor.lux_outside_the_garage) )
     if( pyscript.home_auto_lights_off_has_been_night == 'true' ):
         pyscript.home_auto_lights_off_has_been_night = 'false'
         
-        pyscript.state_goto_all_off();
+        if input_boolean.auto_lights_off == 'on':
+        	pyscript.state_goto_all_off();
 
 
 # Activate morning lights when Thomas gets up
 @time_trigger("once(06:18:00)")
 def morning_lights_thomas():
+    log.info(f"********* THOMAS MORNING ON ***********")
     if binary_sensor.workday_sensor == 'on':
         if switch.eng_heat_a == 'on' or switch.eng_heat_b == 'on':
             pyscript.state_goto_morning();

+ 18 - 16
pyscript/state_goto.py

@@ -30,13 +30,11 @@ def state_goto_all_on():
     light.turn_on(entity_id='light.tradfri_bulb')
     for x in range(2):
         switch.turn_on(entity_id='switch.group_button_all')
-        task.sleep(1.0)
-
-    if light.liv_room_table_lamp == 'off':
-        light.turn_on(entity_id='light.liv_room_table_lamp')
         task.sleep(0.5)
-    if light.liv_room_corner_lamp == 'off':
-        light.turn_on(entity_id='light.liv_room_corner_lamp')
+        light.turn_on(entity_id='light.liv_room_table_lamp',brightness='1')
+        task.sleep(0.5)
+        light.turn_on(entity_id='light.liv_room_corner_lamp',brightness='1')
+        task.sleep(0.5)
 
     pyscript.handle_bedroom_light()
 
@@ -56,6 +54,8 @@ def state_goto_window():
         for x in range(2):
             light.turn_off(entity_id=' light.main_button_2')
             task.sleep(0.5)
+            light.turn_off(entity_id='light.liv_room_corner_lamp')
+            task.sleep(0.5)
     else:                   # From ALL ON
         for x in range(2):
             switch.turn_off(entity_id='switch.group_button_all')
@@ -82,14 +82,14 @@ def state_goto_morning():
             task.sleep(0.5)
             light.turn_on(entity_id=' light.main_button_2')
             task.sleep(0.5)
-        if light.liv_room_corner_lamp == 'off':
-            light.turn_on(entity_id='light.liv_room_corner_lamp')
+            light.turn_on(entity_id='light.liv_room_corner_lamp',brightness='1')
+            task.sleep(0.5)
     elif cs == 2:           # From Window
         for x in range(2):
             light.turn_on(entity_id=' light.main_button_2')
             task.sleep(0.5)
-        if light.liv_room_corner_lamp == 'off':
-            light.turn_on(entity_id='light.liv_room_corner_lamp')
+            light.turn_on(entity_id='light.liv_room_corner_lamp',brightness='1')
+            task.sleep(0.5)
     else:                   # From ALL ON
         for x in range(2):
             switch.turn_off(entity_id='switch.group_button_all')
@@ -99,8 +99,8 @@ def state_goto_morning():
             task.sleep(0.5)
             light.turn_on(entity_id=' light.main_button_4')
             task.sleep(0.5)
-        if light.liv_room_corner_lamp == 'off':
-            light.turn_on(entity_id='light.liv_room_corner_lamp')
+            light.turn_on(entity_id='light.liv_room_corner_lamp',brightness='1')
+            task.sleep(0.5)
     
     pyscript.handle_bedroom_light()
 
@@ -118,6 +118,8 @@ def state_goto_all_off():
         task.sleep(0.5)
         light.turn_off(entity_id='light.liv_room_corner_lamp')
         task.sleep(0.5)
+    input_boolean.movie_mode = 'off'
+
 
 @state_trigger("input_boolean.movie_mode")
 def movie_mode_button_trigger():
@@ -125,11 +127,11 @@ def movie_mode_button_trigger():
     log.info(f"********* MOVIE MODE *********** To:" + input_boolean.movie_mode + " State: " + str(cs) )
     if input_boolean.movie_mode == 'off' and switch.group_button_all == 'on':
         log.info(f"Movie mode, turn lights ON")
-        if light.liv_room_table_lamp == 'off':
-            light.turn_on(entity_id='light.liv_room_table_lamp')
+        for x in range(2):
+            light.turn_on(entity_id='light.liv_room_table_lamp',brightness='1')
+            task.sleep(0.5)
+            light.turn_on(entity_id='light.liv_room_corner_lamp',brightness='1')
             task.sleep(0.5)
-        if light.liv_room_corner_lamp == 'off':
-            light.turn_on(entity_id='light.liv_room_corner_lamp')
  
     else:
         log.info(f"Movie mode, turn lights OFF")

+ 9 - 0
sensors.yaml

@@ -17,3 +17,12 @@
     - name: Exterior light status
       query: "SELECT IF(onOff>0,'on','off') AS status FROM RemoteRxLog.nexaLog where rxTx='R' and remote_id = '20071094' and button='1' order by ts desc LIMIT 1;"
       column: 'status'
+
+
+
+- platform: mqtt
+  name: Temperatur Hällby
+  state_topic: "sensor/outside/temperature"
+  unit_of_measurement: "°C"
+
+