Explorar o código

Shelly,Mocca,Fridge,Automations

pi hai 4 meses
pai
achega
795291b3ff
Modificáronse 10 ficheiros con 291 adicións e 52 borrados
  1. 4 0
      .gitignore
  2. 169 1
      automations.yaml
  3. 5 1
      configuration.yaml
  4. 11 0
      input_booleans.yaml
  5. 4 4
      lights.yaml
  6. 46 9
      mqtt.yaml
  7. 26 24
      pyscript/ext_lights_control.py
  8. 7 4
      pyscript/home_automations.py
  9. 9 0
      pyscript/kitchen.py
  10. 10 9
      pyscript/state_goto.py

+ 4 - 0
.gitignore

@@ -37,3 +37,7 @@ node-red
 
 home-assistant.log.1
 home-assistant.log.fault
+www/._card-mod.js
+www/._mushroom.js
+www/card-mod.js
+www/mushroom.js

+ 169 - 1
automations.yaml

@@ -1 +1,169 @@
-[]
+- id: '1705510128965'
+  alias: Activate coffee brewer timer
+  description: Turns on the coffee brewer electrical switch and starts the timer.
+  trigger:
+  - platform: state
+    entity_id:
+    - input_boolean.activate_coffee_brewer_timer
+    to: 'on'
+  condition: []
+  action:
+  - service: switch.turn_on
+    target:
+      entity_id:
+      - switch.kaffetimer
+      device_id: []
+      area_id: []
+    data: {}
+  - service: timer.start
+    target:
+      entity_id: timer.coffee_brewer_timer
+    data: {}
+  - service: counter.increment
+    target:
+      entity_id: counter.coffee_counter
+    data: {}
+  mode: restart
+- id: '1706284268833'
+  alias: Deactivate coffee brewer timer
+  description: Turns off stuff when manually switching off the timer
+  trigger:
+  - platform: state
+    entity_id:
+    - input_boolean.activate_coffee_brewer_timer
+    from: 'on'
+    to: 'off'
+  - platform: state
+    entity_id:
+    - timer.coffee_brewer_timer
+    from: active
+    to: idle
+  condition: []
+  action:
+  - service: input_boolean.turn_off
+    target:
+      entity_id:
+      - input_boolean.activate_coffee_brewer_timer
+    data: {}
+  - service: timer.cancel
+    target:
+      entity_id: timer.coffee_brewer_timer
+    data: {}
+  - service: switch.turn_off
+    target:
+      entity_id: switch.kaffetimer
+    data: {}
+  mode: single
+- id: '1706284484894'
+  alias: Activate Coffee Brewer at scheduled time
+  description: Starts the coffee brewer timer at the setup time
+  trigger:
+  - platform: time
+    at: input_datetime.coffee_brewer_scheduled_start_time
+  condition:
+  - condition: state
+    entity_id: input_boolean.enable_scheduled_start_of_coffee_brewer
+    state: 'on'
+  action:
+  - service: input_boolean.turn_on
+    target:
+      entity_id:
+      - input_boolean.activate_coffee_brewer_timer
+      device_id: []
+      area_id: []
+    data: {}
+  - service: input_boolean.turn_off
+    target:
+      entity_id: input_boolean.enable_scheduled_start_of_coffee_brewer
+    data: {}
+  mode: single
+- id: '1736266866394'
+  alias: Set Has been Night Flag
+  description: Set that it has been midnight, and that its ok to turn the light on
+  trigger:
+  - platform: time
+    at: 00:30:00
+  action:
+  - service: input_boolean.turn_on
+    target:
+      entity_id:
+      - input_boolean.ext_light_has_been_night
+      - input_boolean.home_auto_lights_off_has_been_night
+    data: {}
+- id: '1736266934946'
+  alias: Set Has Been Day Flag
+  description: ''
+  trigger:
+  - platform: time
+    at: '12:30:00'
+  action:
+  - service: input_boolean.turn_on
+    target:
+      entity_id: input_boolean.ext_light_has_been_day
+- id: '1736267995882'
+  alias: Control Exterior Light
+  description: Control the external lights
+  trigger:
+  - platform: state
+    entity_id: input_boolean.exterior_lights_wanted_state
+  action:
+  - repeat:
+      until:
+      - condition: template
+        value_template: "{{ (states('sensor.exterior_light_status') == states('input_boolean.exterior_lights_wanted_state')
+          and \n   states('light.exterior_lights') == states('input_boolean.exterior_lights_wanted_state')
+          ) or \n   repeat.index >= 5 }}\n"
+      sequence:
+      - service: light.turn_{{ 'off' if is_state('input_boolean.exterior_lights_wanted_state',
+          'off') else 'on' }}
+        target:
+          entity_id:
+          - light.exterior_lights
+          - light.exterior_lights_repeater
+      - delay: 00:01:00
+- id: '1736268207142'
+  alias: Turn on Exterial Lights In The Evening
+  description: ''
+  trigger:
+  - platform: numeric_state
+    entity_id:
+    - sensor.lux_hallby
+    below: 500
+    for:
+      seconds: 0
+  condition:
+  - condition: state
+    entity_id: input_boolean.ext_light_has_been_day
+    state: 'on'
+  action:
+  - service: input_boolean.turn_off
+    target:
+      entity_id: input_boolean.ext_light_has_been_day
+    data: {}
+  - service: input_boolean.turn_on
+    target:
+      entity_id: input_boolean.exterior_lights_wanted_state
+    data: {}
+- id: '1736268250686'
+  alias: Turn Off Exterior Lights In The Morning
+  description: ''
+  trigger:
+  - platform: numeric_state
+    entity_id:
+    - sensor.lux_hallby
+    above: 710
+    for:
+      seconds: 0
+  condition:
+  - condition: state
+    entity_id: input_boolean.ext_light_has_been_night
+    state: 'on'
+  action:
+  - service: input_boolean.turn_off
+    target:
+      entity_id: input_boolean.ext_light_has_been_night
+    data: {}
+  - service: input_boolean.turn_off
+    target:
+      entity_id: input_boolean.exterior_lights_wanted_state
+    data: {}

+ 5 - 1
configuration.yaml

@@ -1,5 +1,5 @@
 config:
-frontend:
+#frontend:
 homeassistant:
 counter:
 logbook:
@@ -24,6 +24,10 @@ logger:
 #    rflink: debug
 #    homeassistant.components.rflink: debug
 
+frontend:
+  extra_module_url:
+    - /local/card-mod.js
+
 mobile_app:
 
 input_button:

+ 11 - 0
input_booleans.yaml

@@ -4,6 +4,17 @@ exterior_lights_wanted_state:
   name: Exterior lights, wanted state
   icon: mdi:lightbulb
 
+ext_light_has_been_day:
+  name: Exterior Light Has Been Day
+  initial: false
+ext_light_has_been_night:
+  name: Exterior Light Has Been Night
+  initial: false
+home_auto_lights_off_has_been_night:
+  name: Home automation lights has been night
+  initial: false
+
+
 movie_mode:
   name: Movie mode
   icon: mdi:movie

+ 4 - 4
lights.yaml

@@ -38,9 +38,9 @@
       name: Liv_room_table_lamp
       type: dimmable
       signal_repetitions: 1
-    newkaku_001ab10a_2:           # Dimmer MWMR-251
-      name: Liv_room_corner_lamp
-      type: dimmable
-      signal_repetitions: 1
+    #newkaku_001ab10a_2:           # Dimmer MWMR-251
+    #  name: Liv_room_corner_lamp
+    #  type: dimmable
+    #  signal_repetitions: 1
 
 

+ 46 - 9
mqtt.yaml

@@ -14,15 +14,9 @@ sensor:
   - name: Frank Temperature
     state_topic: "sensors/outside/frankTemperature"
     unit_of_measurement: "°C"
-
-binary_sensor:
-  - name: "Kitchen worklight switch"
-    unique_id: "kitchen_worklight_switch"
-    state_topic: "kitchen/worklight_switch"
-    availability:
-      - topic: "kitchen/worklight_switch/available"
-    qos: 0
-    device_class: power
+  - name: Garage Ambiant Temperature
+    state_topic: "garage/temps/6f0000106475c728"
+    unit_of_measurement: "°C"
 
 light:
   - schema: json
@@ -50,3 +44,46 @@ light:
     qos: 0
     brightness_scale: 1000
     brightness: true
+
+binary_sensor:
+  - name: "Kitchen worklight switch"
+    unique_id: "kitchen_worklight_switch"
+    state_topic: "kitchen/worklight_switch"
+    availability:
+      - topic: "kitchen/worklight_switch/available"
+    qos: 0
+    device_class: power
+
+  - name: "Kitchen Fridge Door"
+    unique_id: "kitchen_fridge_door"
+    state_topic: "kitchen/fridge/doorState"
+    availability:
+            - topic: "kitchen/fridge/available"
+    qos: 0
+    device_class: door
+    payload_on: "open"
+    payload_off: "closed"
+
+  - name: "Kitchen Freezer Door"
+    unique_id: "kitchen_freezer_door"
+    state_topic: "kitchen/freezer/doorState"
+    availability:
+      - topic: "kitchen/fridge/available"
+    qos: 0
+    device_class: door
+    payload_on: "open"
+    payload_off: "closed"
+
+switch:
+    - name: "Kitchen Audible Alarm"
+      state_topic: "/kitchen/alarm/state"
+      command_topic: "/kitchen/alarm/set"
+      availability:
+      - topic: "kitchen/fridge/available"
+      payload_on: "on"
+      payload_off: "off"
+      state_on: "on"
+      state_off: "off"
+      retain: true
+      qos: 1
+      unique_id: "kitchen_audible_alarm"

+ 26 - 24
pyscript/ext_lights_control.py

@@ -1,41 +1,42 @@
 
-state.persist('pyscript.ext_light_has_been_day','false')
-state.persist('pyscript.ext_light_has_been_night','false')
+#state.persist('pyscript.ext_light_has_been_day','false')
+#state.persist('pyscript.ext_light_has_been_night','false')
 
 # Set that it has been midnight, and that it's ok to turn the light on
-@time_trigger("once(00:30:00)")
-def ext_light_has_been_night():
-    pyscript.ext_light_has_been_night = 'true'
-    pyscript.home_auto_lights_off_has_been_night = 'true'
+#@time_trigger("once(00:30:00)")
+#def ext_light_has_been_night():
+#    pyscript.ext_light_has_been_night = 'true'
+#    pyscript.home_auto_lights_off_has_been_night = 'true'
 
 # Set that it has been noon, and that it's ok to turn off the light
-@time_trigger("once(12:30:00)")
-def ext_light_has_been_day():
-    pyscript.ext_light_has_been_day = 'true'
+#@time_trigger("once(12:30:00)")
+#def ext_light_has_been_day():
+#    pyscript.ext_light_has_been_day = 'true'
 
 
-@state_trigger("sensor.lux_outside_the_garage != 'unknown' and int(sensor.lux_outside_the_garage) < 100", state_hold_false=0 )
-def automate_exterior_lights_on_in_evening():
-    if( pyscript.ext_light_has_been_day == 'true' ):
-        pyscript.ext_light_has_been_day = 'false'
-        input_boolean.exterior_lights_wanted_state = 'on'
+#@state_trigger("sensor.lux_outside_the_garage != 'unknown' and int(sensor.lux_outside_the_garage) < 100", state_hold_false=0 )
+#def automate_exterior_lights_on_in_evening():
+#    if( pyscript.ext_light_has_been_day == 'true' ):
+#        pyscript.ext_light_has_been_day = 'false'
+#        input_boolean.exterior_lights_wanted_state = 'on'
 
-@state_trigger("sensor.lux_outside_the_garage != 'unknown' and int(sensor.lux_outside_the_garage) > 50", state_hold_false=0)
-def automate_exterior_lights_off_in_morning():
-    if( pyscript.ext_light_has_been_night == 'true' ):
-        pyscript.ext_light_has_been_night = 'false'
-        input_boolean.exterior_lights_wanted_state = 'off'
+#@state_trigger("sensor.lux_outside_the_garage != 'unknown' and int(sensor.lux_outside_the_garage) > 50", state_hold_false=0)
+#def automate_exterior_lights_off_in_morning():
+#    if( pyscript.ext_light_has_been_night == 'true' ):
+#        pyscript.ext_light_has_been_night = 'false'
+#        input_boolean.exterior_lights_wanted_state = 'off'
 
 
 
-@state_trigger("input_boolean.exterior_lights_wanted_state")
-@task_unique("control_ext_light", kill_me=True)
-def control_ext_light():
+#@state_trigger("input_boolean.exterior_lights_wanted_state")
+#@task_unique("control_ext_light", kill_me=True)
+#def control_ext_light():
 
     # Set max number of iterations
-    maxIterations = 5
+#    maxIterations = 5
 
     # Loop until we have succeeded to controlling the light
+"""
     while(
              ( (sensor.exterior_light_status != input_boolean.exterior_lights_wanted_state) or 
                (        light.exterior_lights!= input_boolean.exterior_lights_wanted_state) ) and maxIterations > 0
@@ -52,4 +53,5 @@ def control_ext_light():
 
         maxIterations -= 1
     
-    log.info(f"Exit control_ext_light")
+    log.info(f"Exit control_ext_light")
+"""

+ 7 - 4
pyscript/home_automations.py

@@ -1,15 +1,18 @@
 
 # This state is set every midnight by the ext_lights_control-script
-state.persist('pyscript.home_auto_lights_off_has_been_night','false')
+#state.persist('pyscript.home_auto_lights_off_has_been_night','false')
 
 
-@state_trigger("sensor.lux_outside_the_garage != 'unknown' and int(sensor.lux_outside_the_garage) > int(float(input_number.auto_light_off_lux_value))", state_hold_false=0)
+#@state_trigger("sensor.lux_outside_the_garage is not none and sensor.lux_outside_the_garage != 'unknown' and input_number.auto_light_off_lux_value is not none and int(float(sensor.lux_outside_the_garage)) > int(float(input_number.auto_light_off_lux_value))", state_hold_false=0)
+
+
+@state_trigger("sensor.lux_outside_the_garage != None and sensor.lux_outside_the_garage != 'unknown' and 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():
-    if( pyscript.home_auto_lights_off_has_been_night == 'true' ):
+    if( input_boolean.home_auto_lights_off_has_been_night == 'true' ):
 
         log.info(f"********* AUTO LIGHTS OFF *********** Lux: " + str(sensor.lux_outside_the_garage) + " Limit:"+str(input_number.auto_light_off_lux_value))
 
-        pyscript.home_auto_lights_off_has_been_night = 'false'
+        input_boolean.home_auto_lights_off_has_been_night = 'false'
         
         if input_boolean.auto_lights_off == 'on':
             input_select.light_mode = 'All off'

+ 9 - 0
pyscript/kitchen.py

@@ -82,3 +82,12 @@ def handle_kitchen_worklights():
         light.turn_off(entity_id='light.kitchen_worktop_4k')
         light.turn_off(entity_id='light.kitchen_worktop_27k')
 
+
+
+@state_trigger("select.fridge_door_alarm")
+def reset_fridge_alarm_state(value=None, old_value=None):
+    log.info(f"********* FRIDGE ALARM CONFIG *********** To:" + value + " From:" + old_value)
+    if value == 'TEST':
+        #task.sleep(1)  # Wait 1 second
+        select.fridge_door_alarm = old_value
+        mqtt.publish(topic="kitchen/fridge/doorAlarmControl", payload=old_value , retain=True)

+ 10 - 9
pyscript/state_goto.py

@@ -106,11 +106,12 @@ def state_goto_all_on():
     switch.turn_on(entity_id='switch.matsal_piano')
     switch.turn_on(entity_id='switch.koksfonster')
     switch.turn_on(entity_id='switch.sovrum')
+    light.turn_on(entity_id='light.shellydimmer1',brightness_pct=15)
     
     for x in range(2):
         #light.turn_on(entity_id='light.liv_room_table_lamp',brightness='1') # Temp disable when high energy prices
         #task.sleep(0.5)
-        light.turn_on(entity_id='light.liv_room_corner_lamp',brightness='1')
+        
         task.sleep(0.5)
         if( isChristmas ):
             light.turn_on(entity_id=' light.main_button_4') # Christmas lights
@@ -136,11 +137,11 @@ def state_goto_window():
     light.turn_off(entity_id='light.hall_door')
     light.turn_off(entity_id='light.rislampa')
     switch.turn_off(entity_id='switch.sovrum')
+    light.turn_off(entity_id='light.shellydimmer1')
 
     for x in range(2):
         #light.turn_off(entity_id='light.liv_room_table_lamp')
         #task.sleep(0.5)
-        light.turn_off(entity_id='light.liv_room_corner_lamp')
         task.sleep(0.5)
         if( isChristmas ):
             light.turn_on(entity_id=' light.main_button_4') # Christmas lights
@@ -165,10 +166,10 @@ def state_goto_morning():
     light.turn_on(entity_id='light.hall_door', brightness=25, color_temp_kelvin=2570)
     light.turn_off(entity_id='light.rislampa')
     switch.turn_off(entity_id='switch.sovrum')
+    light.turn_off(entity_id='light.shellydimmer1')
+
 
     for x in range(2):
-        #light.turn_on(entity_id='light.liv_room_corner_lamp',brightness='1')
-        light.turn_off(entity_id='light.liv_room_corner_lamp')
         task.sleep(0.5)
         if( isChristmas ):
             light.turn_off(entity_id=' light.main_button_4') # Christmas lights
@@ -191,11 +192,12 @@ def state_goto_all_off():
     switch.turn_off(entity_id='switch.matsal_altandorr')
     switch.turn_off(entity_id='switch.matsal_piano')
     switch.turn_off(entity_id='switch.sovrum')
+    light.turn_off(entity_id='light.shellydimmer1')
 
     for x in range(2):
         #light.turn_off(entity_id='light.liv_room_table_lamp')  # Temp disable when high energy prices
         #task.sleep(0.5)
-        light.turn_off(entity_id='light.liv_room_corner_lamp')
+        
         task.sleep(0.5)
         if( isChristmas ):
             light.turn_off(entity_id=' light.main_button_4') # Christmas lights
@@ -210,18 +212,17 @@ def movie_mode_button_trigger():
     log.info(f"********* MOVIE MODE *********** To:" + input_boolean.movie_mode + " State: " + input_select.light_mode )
     if input_boolean.movie_mode == 'off' and input_select.light_mode == 'All on':
         log.info(f"Movie mode, turn lights ON")
+        light.turn_on(entity_id='light.shellydimmer1',brightness_pct=15)
         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)
  
     else:
         log.info(f"Movie mode, turn lights OFF")
+        light.turn_off(entity_id='light.shellydimmer1')
         for x in range(2):
             light.turn_off(entity_id='light.liv_room_table_lamp')
             task.sleep(0.5)
-            light.turn_off(entity_id='light.liv_room_corner_lamp')
-            task.sleep(0.5)
+