『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 5865|回复: 9

关于自动开关灯的自动化优化

[复制链接]

175

主题

2956

帖子

7555

积分

超级版主

我就是六神

Rank: 8Rank: 8

积分
7555
金钱
4574
HASS币
398

活跃会员教程狂人灌水之王

QQ
发表于 2019-8-30 01:00:45 | 显示全部楼层 |阅读模式
本帖最后由 jyz_0501 于 2019-8-30 01:04 编辑

以前利用绿米人体感应器 做开关灯的操作 一直是写两个自动化, 一个是开灯 一个是关灯,这样房间多了,光自动开关灯就要双倍的。
实在是有些臃肿

强迫症的我决定换掉它。

版本一:(以前的版本)
- id: 4d9ac4ca4fb94648bf0ccbec2e450343
  alias: 自动开次卧灯
  trigger:
  - entity_id: binary_sensor.motion_sensor_158d0002b70e92
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: state
    entity_id: light.guestroomlight
    state: 'off'
  - below: '10'
    condition: numeric_state
    entity_id: sensor.illumination_158d0002b70e92
  action:
  - data:
      entity_id: light.guestroomlight
    entity_id: light.guestroomlight
    service: light.turn_on



- id: '15595744010686'
  alias: 自动关次卧灯
  trigger:
  - entity_id: binary_sensor.motion_sensor_158d0002b70e92
    from: 'on'
    platform: state
    to: 'off'
  condition:
  - condition: state
    entity_id: light.guestroomlight
    state: 'on'
  action:
  - data:
      entity_id: light.guestroomlight
    service: light.turn_off


版本二:(优化后)
- id: '1567093370829'
  alias: 自动开关玄关灯
  trigger:
    entity_id: binary_sensor.motion_sensor_158d000237a917
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: state
    entity_id: switch.wall_switch_left_158d0002425dcb
    state: 'off'
  action:
  - data:
      entity_id: switch.wall_switch_left_158d0002425dcb
    service: switch.turn_on
  - timeout: 0:10:00
    wait_template: '{{is_state("binary_sensor.motion_sensor_158d000237a917","off")}}'
  - data:
      entity_id: switch.wall_switch_left_158d0002425dcb
    service: switch.turn_off


版本三:(再次优化)
event触发时间比state的周期要短,state是120秒,event是60秒
- id: '1567093370829'
  alias: 自动开关玄关灯
  trigger:
  - event_data:
      entity_id: binary_sensor.motion_sensor_158d000237a917
    event_type: xiaomi_aqara.motion
    platform: event
  condition:
  - condition: state
    entity_id: switch.wall_switch_left_158d0002425dcb
    state: 'off'
  action:
  - data:
      entity_id: switch.wall_switch_left_158d0002425dcb
    service: switch.turn_on
  - timeout: 0:10:00
    wait_template: '{{is_state("binary_sensor.motion_sensor_158d000237a917","off")}}'
  - data:
      entity_id: switch.wall_switch_left_158d0002425dcb
    service: switch.turn_off



回复

使用道具 举报

15

主题

656

帖子

2826

积分

金牌会员

Rank: 6Rank: 6

积分
2826
金钱
2170
HASS币
91

教程狂人

QQ
发表于 2019-8-30 07:18:28 | 显示全部楼层
10分钟等待超时,一直等待不行吗?
回复

使用道具 举报

18

主题

689

帖子

3768

积分

元老级技术达人

积分
3768
金钱
3069
HASS币
60
发表于 2019-8-30 07:53:31 | 显示全部楼层
本帖最后由 houhd 于 2019-8-30 08:00 编辑

我实话,关灯这个动作,2分钟我都觉得久。楼主这是10分钟么?还有就是小米那光感好鸡肋,不实时,从亮到暗,数值经常要很久才能降下来,所以我都直接放弃以这个光感做判断条件了。这个event原来还有这操作,我试试,谢谢。
回复

使用道具 举报

7

主题

1975

帖子

5663

积分

论坛元老

流水无味

Rank: 8Rank: 8

积分
5663
金钱
3688
HASS币
145

灌水之王

发表于 2019-8-30 11:16:11 | 显示全部楼层
houhd 发表于 2019-8-30 07:53
我实话,关灯这个动作,2分钟我都觉得久。楼主这是10分钟么?还有就是小米那光感好鸡肋,不实时,从亮到暗 ...

光感是很坑,我每天稍微暗点过去第一次灯经常不开,
后来发现光感数值太高, 后来有几个就按时间来了
回复

使用道具 举报

6

主题

738

帖子

5588

积分

论坛元老

Rank: 8Rank: 8

积分
5588
金钱
4845
HASS币
20
发表于 2019-8-30 11:29:51 | 显示全部楼层
感觉还是按日出日落时间靠谱一些
回复

使用道具 举报

10

主题

198

帖子

1739

积分

金牌会员

Rank: 6Rank: 6

积分
1739
金钱
1541
HASS币
0
发表于 2019-8-30 12:58:42 | 显示全部楼层
mitu 发表于 2019-8-30 11:29
感觉还是按日出日落时间靠谱一些

正常天气日出日落是没问题的,但阴雨天气就不够用了。
小米的这个人体光感确实鸡肋,我比较喜欢用小米网关的光感,放在不遮阳的地方,根据不同的光照强度,设置不同位置的开灯条件,而且网关可以实时传送数据,较为灵敏。
回复

使用道具 举报

175

主题

2956

帖子

7555

积分

超级版主

我就是六神

Rank: 8Rank: 8

积分
7555
金钱
4574
HASS币
398

活跃会员教程狂人灌水之王

QQ
 楼主| 发表于 2019-8-30 16:01:41 | 显示全部楼层
xieahui 发表于 2019-8-30 11:16
光感是很坑,我每天稍微暗点过去第一次灯经常不开,
后来发现光感数值太高, 后来有几个就按时间来了 ...

有时阴天 下午2 3点就很黑了~~
回复

使用道具 举报

175

主题

2956

帖子

7555

积分

超级版主

我就是六神

Rank: 8Rank: 8

积分
7555
金钱
4574
HASS币
398

活跃会员教程狂人灌水之王

QQ
 楼主| 发表于 2019-8-30 16:03:30 | 显示全部楼层
houhd 发表于 2019-8-30 07:53
我实话,关灯这个动作,2分钟我都觉得久。楼主这是10分钟么?还有就是小米那光感好鸡肋,不实时,从亮到暗 ...

2分钟我也觉的久 but 除非有人体计数,目前也就这个比较好用了。

10分钟是超时时间,我觉得10分钟够用了,这个数值其实放在平时意义不大,主要是为了不占用监听资源。
回复

使用道具 举报

175

主题

2956

帖子

7555

积分

超级版主

我就是六神

Rank: 8Rank: 8

积分
7555
金钱
4574
HASS币
398

活跃会员教程狂人灌水之王

QQ
 楼主| 发表于 2019-8-30 16:05:33 | 显示全部楼层
本帖最后由 jyz_0501 于 2019-8-30 16:14 编辑

实际上还有第四个版本,集所有灯于一个自动化,但是又过于复杂,有点事去了智能家居和自动化的意义了
################################################
########## Motion Lights Auto On/Off ###########
################################################
  - id: motion_lights
    alias: Motion Lights
    trigger:
      - platform: state
        entity_id: 
          - binary_sensor.computer_room_motion
          - binary_sensor.living_room_motion
          - binary_sensor.kitchen_motion_sensor
          - binary_sensor.dining_room_motion_sensor
          - binary_sensor.craft_room_motion_sensor
          - binary_sensor.half_bathroom_motion_sensor
          - binary_sensor.poop_closet_motion
          - binary_sensor.master_bath_motion
          - binary_sensor.guest_bathroom_motion
          - binary_sensor.master_bedroom_motion
        to: 'on'
      - platform: state
        entity_id:
          - binary_sensor.guest_bathroom_motion
          - binary_sensor.master_bath_motion
          - binary_sensor.dining_room_motion_sensor
        to: 'off'
        for:
          minutes: 20
      - platform: state
        entity_id:
          - binary_sensor.computer_room_motion
          - binary_sensor.craft_room_motion_sensor
          - binary_sensor.living_room_motion
          - binary_sensor.master_bedroom_motion
        to: 'off'
        for:
          minutes: 15
      - platform: state
        entity_id:
          - binary_sensor.kitchen_motion_sensor
          - binary_sensor.half_bathroom_motion_sensor
          - binary_sensor.poop_closet_motion
        to: 'off'
        for:
          minutes: 2
    condition:
      ### Ensure Motion Lights aren't disabled
      - condition: state
        entity_id: input_boolean.block_all_motion_lights
        state: 'off'
      ### Ensure it is dark outside for certain lights
      - condition: template
        value_template: >
          {% set trigger_entity = trigger.entity_id %}
          {% if trigger_entity == 'binary_sensor.computer_room_motion' or trigger_entity == 'binary_sensor.living_room_motion' %}
            {% if is_state("input_boolean.dark_outside", "on") %}
              {% if trigger_entity == 'binary_sensor.living_room_motion' %}
                {% if is_state("sensor.harmony", "PowerOff") %}
                  true
                {% else %}
                  false
                {% endif %}
              {% else %}
                true
              {% endif %}
            {% else %}
              false
            {% endif %}
          {% else %}
            true
          {% endif %}
      - condition: template
        value_template: >
          {% set trigger_entity = trigger.entity_id %}
          {% if trigger_entity == 'binary_sensor.craft_room_motion_sensor' and is_state("input_boolean.disable_craft_room_motion", "on") %}
            false
          {% else %}
            true
          {% endif %}
      - condition: template
        value_template: >
          {% set trigger_entity = trigger.entity_id %}
          {% if trigger_entity == 'binary_sensor.master_bedroom_motion' and is_state("input_boolean.disable_master_bedroom_motion", "on") %}
            false
          {% else %}
            true
          {% endif %}
    action:
      ### Determine light/group that goes with motion detector
      - service_template: 'homeassistant.turn_{{trigger.to_state.state}}'
        data_template:
          entity_id: >
            {% set trigger_entity = trigger.entity_id %}
            {% set to_state = trigger.to_state.state %}
            {% if trigger_entity == 'binary_sensor.computer_room_motion' %}
              group.computer_room
            {% elif trigger_entity == 'binary_sensor.kitchen_motion_sensor' %}
              {% if to_state == 'off' %}
                group.kitchen
              {% else %}
                switch.kitchen_light
              {% endif %}
            {% elif trigger_entity == 'binary_sensor.dining_room_motion_sensor' %}
              group.dining_room
            {% elif trigger_entity == 'binary_sensor.craft_room_motion_sensor' %} 
              group.craft_room
            {% elif trigger_entity == 'binary_sensor.half_bathroom_motion_sensor' %} 
              {% if to_state == 'off' %}
                group.half_bath_light_fan
              {% else %}
                group.half_bath
              {% endif %}
            {% elif trigger_entity == 'binary_sensor.poop_closet_motion' %} 
              switch.poop_closet_light
            {% elif trigger_entity == 'binary_sensor.master_bath_motion' %} 
              {% if to_state == 'off' %}
                group.master_bath
              {% else %}
                switch.master_bath_light
              {% endif %}
            {% elif trigger_entity == 'binary_sensor.guest_bathroom_motion' %} 
              group.guest_bath
            {% elif trigger_entity == 'binary_sensor.master_bedroom_motion' %} 
              switch.master_light
            {% elif trigger_entity == 'binary_sensor.living_room_motion' %}
              switch.living_room_light
            {% else %}
              input_boolean.test1
            {% endif %}

回复

使用道具 举报

11

主题

313

帖子

1324

积分

金牌会员

Rank: 6Rank: 6

积分
1324
金钱
1011
HASS币
10
发表于 2021-4-15 22:35:35 | 显示全部楼层
jyz_0501 发表于 2019-8-30 16:05
实际上还有第四个版本,集所有灯于一个自动化,但是又过于复杂,有点事去了智能家居和自动化的意义了

...

呃 确实复杂 看了半天迷迷糊糊
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-4-26 18:23 , Processed in 1.538043 second(s), 33 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表