자동차씬에서는 하리~라는 이름으로, IOT/인테리어쪽에서는 하리바바라는 닉으로 놀고 있는 문과 아저씨입니다.
작년에 인테리어를 하면서 IOT를 나름 빡씨게 적용해봤었는데, 스마트싱스라는 플랫폼이 나름 통합성도 좋고 엣지드라이버를 통한 비인증 기기 호환성도 상당히 좋았음에도.. 뭔가 해소되지 않는 것들이 좀 있었습니다.
여튼 그런 이유로 HOME ASSISTANT YELLOW라는 나름 HA 레퍼런스 기기를 도입하여 이런 저런 삽질을 한달간 하고..
부족한 능력이지만, 제 나름대로 만들어본 자동화들을 소개해보려 합니다.
------------------
1.특정 카운터 센서 수치 변경 시, 타 센서 수치도 연동해서 달라지게 해보자.
저희집에는 노란 점선 박스 자리에 카운터 센서가 있습니다.
현관의 센서는 전체 인원을 감지하고, 거실입구에서 거실의 인원을 감지할 수 있어서 그런대로 잘 써먹고 있지요.
근데, 여기서 좀 맘에 안드는건.. 빈집에 제가 들어가서 안방에 들어갈 경우,
현관(전체) : 1
거실 : 1
옷방 : 1
안방 : 1
안방 욕실 : 0
이렇게 표시되는게 맘에 안들더라구요. 실제 재실 인원이 표시되면 좋겠는데.. 이게 보기 싫었습니다.
이럴 경우
현관(전체) : 1
거실 : 0
옷방 : 0
안방 : 1
안방 욕실 : 0
이렇게 나오길 바래서.. 코딩을 한번 해봤습니다.
참고를 위해 저희집 entity까지 적어봅니다.
안방 : number.0x00158d0005bbcdab_people
안방 욕실 : number.0x00158d0005bbcdc0_people
옷방 : number.0x00158d000853662a_people
거실 : number.0x00158d0005bbcf37_people
현관 : number.0x00158d0005bbce49_people
다른 분들이 참고하실때에는 이 entity id를 수정하셔야합니다.
코드 나갑니다.
코드는 2개로 이루어져있습니다.
alias: "[테스트] 안방 또는 안방 욕실의 카운터 가감시, 옷방 카운터 감가" description: "" trigger: - platform: state entity_id: - number.0x00158d0005bbcdab_people - number.0x00158d0005bbcdc0_people condition: [] action: - choose: - conditions: - condition: template value_template: >- {{ trigger.from_state.state | int < trigger.to_state.state | int }} sequence: - service: number.set_value target: entity_id: number.0x00158d000853662a_people data: value: "{{ (states('number.0x00158d000853662a_people') | int) - 1 }}" - conditions: - condition: template value_template: >- {{ trigger.from_state.state | int > trigger.to_state.state | int }} sequence: - service: number.set_value target: entity_id: number.0x00158d000853662a_people data: value: "{{ (states('number.0x00158d000853662a_people') | int) + 1 }}" |
여기까지는 좋았는데 다음에 해야할건..
옷방의 숫자가 증가 또는 감소할때 거실의 숫자가 달라져야 하는데.. 이렇게 되면.. 욕실이나 안방에서 나왔을때도 옷방의 숫자가 달라지기 때문에, 거실 숫자가 증가 또는 감소하는 문제가 생기더라구요.. 그래서 예외를 적용했습니다.
2. 옷방의 가 증가하거나 감소하면, 거실의 숫자를 감소시키거나 증가시킨다. 단, 안방과 안방 욕실의 숫자 변화로 인해 옷방의 숫자가 달라질 경우, 거실 숫자는 변경되서는 안된다.
이렇게했더니.. 모순이 생겨서.. 작동이 안되는 문제가 발생..ㅠㅠ
옷방이 거실에 영향을 주는 조건을 숫자가 아닌 물리적인 움직임이 감지됐음을 의미하는 STATE (IN/OUT)을 이용하여 수정해봤습니다. (회사에서 코딩만 해놨고, 집에 가봐야 알 듯 합니다.)
alias: "[테스트] 옷방 카운터 상태 변경(in/out) 시, 거실 카운터 감가" description: "" trigger: - platform: state entity_id: sensor.0x00158d000853662a_status condition: - condition: template value_template: "{{ trigger.to_state.state in ['in', 'out'] }}" action: - choose: - conditions: - condition: template value_template: "{{ trigger.to_state.state == 'in' }}" sequence: - service: number.set_value target: entity_id: number.0x00158d0005bbcf37_people data: value: "{{ (states('number.0x00158d0005bbcf37_people') | int) - 1 }}" - conditions: - condition: template value_template: "{{ trigger.to_state.state == 'out' }}" sequence: - service: number.set_value target: entity_id: number.0x00158d0005bbcf37_people data: value: "{{ (states('number.0x00158d0005bbcf37_people') | int) + 1 }}" |
2.네스트 온도 조절기 패턴 난방
최근 난방비 급등으로 인해, 패턴 난방에 대한 관심이 많아지신걸로 알고 있습니다. 저또한.. 난방비 폭탄의 피폭자로...
뭔가를 해야겠다는 생각이 들어서, 네스트 온도 조절기의 패턴 난방을 만들어봤습니다.
기본적으로 네스트는 수동으로 패턴을 설정할 수 있긴 하지만, 최소 구동 시간이 1시간이기때문에.. 제가 원하는 수준으로 제어가 되지 않았고. 그런 이유로 YAML을 건드리게 되었습니다.
이 역시 2개의 코드로 만들어져있습니다.
- 난방이 켜지면 XX분간 유지하고 ECO로 전환
- ECO로 전환되면 XX로 유지하고 난방으로 전환
첫번째 코드 나갑니다.
alias: 안방 난방 15분 후 ECO 전환 description: "" trigger: - platform: device device_id: 5a8204c87e3ddd263fb623491195ae61 domain: climate entity_id: climate.anbang type: hvac_mode_changed to: heat condition: [] action: - delay: hours: 0 minutes: 15 seconds: 0 milliseconds: 0 - device_id: 5a8204c87e3ddd263fb623491195ae61 domain: climate entity_id: climate.anbang type: set_preset_mode preset_mode: eco mode: single |
두번째 코드
alias: 안방 ECO 45분 후 난방 전환 description: "" trigger: - platform: state entity_id: climate.anbang attribute: preset_mode to: eco condition: [] action: - delay: hours: 0 minutes: 45 seconds: 0 milliseconds: 0 - device_id: 5a8204c87e3ddd263fb623491195ae61 domain: climate entity_id: climate.anbang type: set_preset_mode preset_mode: none mode: single |
이렇게만 해놓으면 되고.. 다른 자동화로 난방을 ON, OFF 시키고 싶을때는 위에 있는 자동화를 건드리지 않고, 그냥 난방 hvac_mode를 heat로 하거나 off시키면 됩니다.
하나의 자동화로도 구현하는데에 성공은 했는데.. 뭔가 이상하게 작동될때가 있어서 그냥 두개로 쪼개놨습니다.
3.원버튼(스위치)으로 커튼 컨트롤
버튼 하나로 커튼을 열고, 닫고, 일시정지시키는 코드입니다.
스마트 싱스 쓰던 초창기.. 선행 조건이라는 개념을 잘 몰라서.. 한번 누르면 열고, 두번 누르면 닫고 이렇게 썼었는데...
움직이는 중에 누르면 일시정지되고, 다시 누르면 열리거나 닫히는 기능까지 들어가있습니다.
밑의 코드는 트리거가 3개 (지그비 버튼 2개, 릴레이 1개)인 구성이니.. 따다 쓰실분이라면 트리거 필요한만큼 줄이거나 늘리시면 되겠습니다.
alias: 거실 릴레이/리모콘 - 커튼 자동화 description: "" trigger: - platform: device type: changed_states device_id: 996be1ec5aa970e2904cad49939be1dc entity_id: switch.0x84b4dbfffebc5937_l2 domain: switch - platform: device domain: mqtt device_id: 17b3e07bd894474b68365a3a9c0066ae type: action subtype: button_1_press discovery_id: 0x001788010d135288 action_button_1_press - platform: device domain: mqtt device_id: aa073ffddd4a6c3a36321b0c711fc5d0 type: action subtype: 2_single discovery_id: 0xcc86ecfffe5cc68b action_2_single condition: - condition: numeric_state entity_id: number.0x00158d0005bbce49_people above: 0.5 action: - service: cover.toggle data: {} target: device_id: - 037ce4793223d066e44de1fe7f680d45 - 4ebc4389a8c3e0abdaf61191af0a6013 - if: - type: is_on condition: device device_id: 037ce4793223d066e44de1fe7f680d45 entity_id: binary_sensor.0x00158d00067280e4_running domain: binary_sensor - type: is_on condition: device device_id: 4ebc4389a8c3e0abdaf61191af0a6013 entity_id: binary_sensor.0x00158d0006723cf4_running domain: binary_sensor then: - service: cover.stop_cover data: {} target: device_id: - 037ce4793223d066e44de1fe7f680d45 - 4ebc4389a8c3e0abdaf61191af0a6013 mode: single |
4.원버튼 온도 최적화
제맘대로 정한 이름입니다. 누워있거나 컴 앞에 있을때.. 굳이 난방이나 에어컨 리모콘 찾기도 싫은.. 게으름이 정점을 찍은 상태일때...버튼 하나만 누르면 되는 기능입니다.
더울때 누르면 에어컨이 켜지고, 추울때 누르면 난방이 켜지고, 이 둘중 하나가 작동중일때 누르면 켜져있던게 꺼지는 심플하지만 매우 편리한 기능입니다.
이역시 자동화 2개가 필요합니다.
더울때 누르면 냉방, 추울때 누르면 난방 켜기
위의 상태일때 또 누르면 켜진거 끄기
첫번째 코드
alias: 컴퓨터방 리모콘 3번 - 원버튼 온도 제어 ON description: "" trigger: - platform: device domain: mqtt device_id: bb3bb61078fb646b7a2dfa870ef3bf50 type: action subtype: 3_single discovery_id: 0xcc86ecfffe5cc4e6 action_3_single condition: - condition: template value_template: | {{ states('sensor.keombang_temperature')|float > 25 or states('sensor.keombang_temperature')|float <= 22 }} action: - choose: - conditions: - condition: template value_template: | {{ states('sensor.keombang_temperature')|float > 25 }} - condition: state entity_id: climate.keombang_eeokeon state: "off" sequence: - service: climate.turn_on target: entity_id: climate.keombang_eeokeon data: {} - service: climate.set_hvac_mode data: hvac_mode: cool target: entity_id: climate.keombang_eeokeon - conditions: - condition: template value_template: | {{ states('sensor.keombang_temperature')|float <= 22 }} - condition: state entity_id: climate.keombang state: "off" sequence: - service: climate.turn_on target: entity_id: climate.keombang data: {} - service: climate.set_hvac_mode data: hvac_mode: heat target: entity_id: climate.keombang default: [] mode: single |
두번째 코드
alias: 컴퓨터방 리모콘 3번 - 원버튼 온도 제어 OFF description: "" trigger: - platform: device domain: mqtt device_id: bb3bb61078fb646b7a2dfa870ef3bf50 type: action subtype: 3_single discovery_id: 0xcc86ecfffe5cc4e6 action_3_single condition: - condition: or conditions: - condition: state entity_id: climate.keombang_eeokeon state: cool - condition: state entity_id: climate.keombang state: heat action: - choose: - conditions: - condition: state entity_id: climate.keombang_eeokeon state: cool sequence: - service: climate.set_hvac_mode data: hvac_mode: "off" target: entity_id: climate.keombang_eeokeon - conditions: - condition: state entity_id: climate.keombang state: heat sequence: - service: climate.set_hvac_mode data: hvac_mode: "off" target: entity_id: climate.keombang default: [] mode: single |
5.카운터 센서 값 비교 후 조명 제어.
저희집은 현관을 들어선 후, 긴 복도를 지나야 거실이 나오는데, 집에 들어온 후 거실에 들어선 이후에는 복도 공간에 딱히 조명이 들어올 필요가 없습니다.
그래서 현관에 카운터 센서 1개, 거실 입구쪽에 또 1개를 달아놓고, 현관과 거실의 카운터 센서 숫자가 동일할 경우 = 복도 조명을 쓰는 자동화를 만들었습니다. 카운터 말고 FP1같은 재실 센서로도 구현은 가능하지만.. 이미 있는 기기들만으로 해결해보고 싶어서 카운터 센서 2개를 활용해서 만들어봤습니다.
alias: 현관-거실 카운터 센서 비교 후 복도 조명 OFF description: "" trigger: - platform: template value_template: >- {{ states('number.0x00158d0005bbcf37_people') == states('number.0x00158d0005bbce49_people') }} condition: [] action: - type: turn_off device_id: ba35383030a03f8c6f4d31d70f483c00 entity_id: light.bogdo_teuraeg domain: light mode: single |
별거 아닌것 같지만... 1989년 GW-BASIC이후로 까만화면에 글자를 쳐본적이 없던 아저씨라.. 힘겹게 만들었습니다. ㅎㅎ
아무쪼록 도움되시는 분들 계시면 좋겠습니다.
그럼 끗.
HA하시는 분들은 당연히 아시겠지만, 본문의 소스에 있는 entity id는 각자 사용하시는 기기에 맞춰 변경하셔야 합니다.
저도 ioT 적용해보고 열공하는 한사람입니다~~
열공해서 적용해보겠습니다.
감사합니다~~*^_____^*🌼🌻