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

 找回密码
 立即注册
查看: 12766|回复: 12

[已解决] 交流一个阳台自动关灯的问题【利用百度ai完美解决了】

[复制链接]

46

主题

641

帖子

4411

积分

元老级技术达人

积分
4411
金钱
3740
HASS币
120
发表于 2020-3-6 15:46:45 来自手机 | 显示全部楼层 |阅读模式
本帖最后由 evantalk 于 2020-9-2 12:01 编辑

阳台的门装了门窗传感器,能实现开门自动亮灯,关门自动熄灯。但是有时候也有人在外面,要关门的情况,怎么办?
感谢萝卜大神共享的方案 @antsunzj应用云台摄像头+ai人体分析判断人体是否存在    https://bbs.hassbian.com/thread-8097-1-1.html

原理就是通过摄像头截图,上传百度ai,百度“人流量统计”能从图片中识别出有多好个人,如果人数为0可以关灯
正好我阳台有海康威视的摄像头,完美解决了,过程中遇到几个坑跟大家分享一下:

1,新款的摄像头截图url需要摘要认证(用户名和密码),这个用node-red也是可以解决的
摘要认证.PNG


2,为了防止人走到边缘误判,可以检查2遍


献上我的flow
[
    {
        "id": "46cfc3b5.ec68cc",
        "type": "tab",
        "label": "后院自动关灯",
        "disabled": false,
        "info": ""
    },
    {
        "id": "b5a42f15.0fc0c",
        "type": "server",
        "z": "",
        "name": "Home Assistant",
        "addon": true
    },
    {
        "id": "514d15d8.48056c",
        "type": "baidu-face-configurator",
        "z": "",
        "name": "人流量统计",
        "client_id": "换成自己的",
        "client_secret": "换成自己的"
    },
    {
        "id": "961df4c2.d34e88",
        "type": "ui_base",
        "theme": {
            "name": "theme-light",
            "lightTheme": {
                "default": "#0094CE",
                "baseColor": "#0094CE",
                "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
                "edited": true,
                "reset": false
            },
            "darkTheme": {
                "default": "#097479",
                "baseColor": "#097479",
                "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
                "edited": false
            },
            "customTheme": {
                "name": "Untitled Theme 1",
                "default": "#4B7930",
                "baseColor": "#4B7930",
                "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
            },
            "themeState": {
                "base-color": {
                    "default": "#0094CE",
                    "value": "#0094CE",
                    "edited": false
                },
                "page-titlebar-backgroundColor": {
                    "value": "#0094CE",
                    "edited": false
                },
                "page-backgroundColor": {
                    "value": "#fafafa",
                    "edited": false
                },
                "page-sidebar-backgroundColor": {
                    "value": "#ffffff",
                    "edited": false
                },
                "group-textColor": {
                    "value": "#1bbfff",
                    "edited": false
                },
                "group-borderColor": {
                    "value": "#ffffff",
                    "edited": false
                },
                "group-backgroundColor": {
                    "value": "#ffffff",
                    "edited": false
                },
                "widget-textColor": {
                    "value": "#111111",
                    "edited": false
                },
                "widget-backgroundColor": {
                    "value": "#0094ce",
                    "edited": false
                },
                "widget-borderColor": {
                    "value": "#ffffff",
                    "edited": false
                },
                "base-font": {
                    "value": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
                }
            },
            "angularTheme": {
                "primary": "indigo",
                "accents": "blue",
                "warn": "red",
                "background": "grey"
            }
        },
        "site": {
            "name": "Node-RED Dashboard",
            "hideToolbar": "false",
            "allowSwipe": "false",
            "lockMenu": "false",
            "allowTempTheme": "true",
            "dateFormat": "DD/MM/YYYY",
            "sizes": {
                "sx": 48,
                "sy": 48,
                "gx": 6,
                "gy": 6,
                "cx": 6,
                "cy": 6,
                "px": 0,
                "py": 0
            }
        }
    },
    {
        "id": "8f72f829.a59ea8",
        "type": "server",
        "z": "",
        "name": "Home Assistant",
        "legacy": true,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open"
    },
    {
        "id": "6a6962b1.5468fc",
        "type": "server-state-changed",
        "z": "46cfc3b5.ec68cc",
        "name": "后院开灯",
        "server": "b5a42f15.0fc0c",
        "version": 1,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "switch.wall_switch_ln_left_158d0002114b19",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "on",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 2,
        "output_only_on_state_change": true,
        "x": 280,
        "y": 660,
        "wires": [
            [
                "33e78dfc.6de672"
            ],
            []
        ]
    },
    {
        "id": "857d188e.b948b8",
        "type": "http request",
        "z": "46cfc3b5.ec68cc",
        "name": "海康威视摄像头抓图",
        "method": "GET",
        "ret": "bin",
        "paytoqs": "body",
        "url": "http://192.168.1.3/ISAPI/Streaming/channels/100/picture?videoResolutionWidth=1920&videoResolutionHeight=1080",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "digest",
        "x": 680,
        "y": 460,
        "wires": [
            [
                "405fcaf4.cf3194"
            ]
        ]
    },
    {
        "id": "405fcaf4.cf3194",
        "type": "base64",
        "z": "46cfc3b5.ec68cc",
        "name": "base64编码",
        "action": "",
        "property": "payload",
        "x": 750,
        "y": 560,
        "wires": [
            [
                "afec3153.5879"
            ]
        ]
    },
    {
        "id": "afec3153.5879",
        "type": "change",
        "z": "46cfc3b5.ec68cc",
        "name": "转换参数名称",
        "rules": [
            {
                "t": "move",
                "p": "payload",
                "pt": "msg",
                "to": "image",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 820,
        "y": 660,
        "wires": [
            [
                "bb33f0e5.46b86"
            ]
        ]
    },
    {
        "id": "87d4737f.de24d",
        "type": "delay",
        "z": "46cfc3b5.ec68cc",
        "name": "",
        "pauseType": "delay",
        "timeout": "2",
        "timeoutUnits": "minutes",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "x": 480,
        "y": 400,
        "wires": [
            [
                "857d188e.b948b8"
            ]
        ]
    },
    {
        "id": "bb33f0e5.46b86",
        "type": "baidu-body-num",
        "z": "46cfc3b5.ec68cc",
        "name": "百度ai统计图片中的人数",
        "baiduface": "514d15d8.48056c",
        "image": "",
        "show": false,
        "x": 1110,
        "y": 560,
        "wires": [
            [
                "67c656c2.394088"
            ],
            []
        ]
    },
    {
        "id": "67c656c2.394088",
        "type": "switch",
        "z": "46cfc3b5.ec68cc",
        "name": "判断人数是否为零",
        "property": "payload.person_num",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "0",
                "vt": "str"
            },
            {
                "t": "gt",
                "v": "0",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 1270,
        "y": 260,
        "wires": [
            [
                "ec6459c0.e12648"
            ],
            [
                "87d4737f.de24d"
            ]
        ]
    },
    {
        "id": "ef751980.148608",
        "type": "api-call-service",
        "z": "46cfc3b5.ec68cc",
        "name": "后院关灯",
        "server": "b5a42f15.0fc0c",
        "version": 1,
        "debugenabled": false,
        "service_domain": "switch",
        "service": "turn_off",
        "entityId": "switch.wall_switch_ln_left_158d0002114b19",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 2040,
        "y": 160,
        "wires": [
            []
        ]
    },
    {
        "id": "b6c9443a.d2c498",
        "type": "api-call-service",
        "z": "46cfc3b5.ec68cc",
        "name": "语音播报",
        "server": "b5a42f15.0fc0c",
        "version": 1,
        "debugenabled": false,
        "service_domain": "media_player",
        "service": "play_media",
        "entityId": "media_player.mopidy",
        "data": "{"media_content_type":"music","media_content_id":"http://192.168.2.18:8123/local/sound/lutai_off_light.mp3"}",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 2120,
        "y": 700,
        "wires": [
            []
        ]
    },
    {
        "id": "d1d08464.f725b8",
        "type": "delay",
        "z": "46cfc3b5.ec68cc",
        "name": "",
        "pauseType": "delay",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "x": 2120,
        "y": 600,
        "wires": [
            [
                "b6c9443a.d2c498"
            ]
        ]
    },
    {
        "id": "10fac6cd.0d5779",
        "type": "api-call-service",
        "z": "46cfc3b5.ec68cc",
        "name": "打开功放",
        "server": "b5a42f15.0fc0c",
        "version": 1,
        "debugenabled": false,
        "service_domain": "script",
        "service": "turn_on",
        "entityId": "script.prepare_for_tts",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 2100,
        "y": 500,
        "wires": [
            [
                "d1d08464.f725b8"
            ]
        ]
    },
    {
        "id": "fd1b23fb.b4dbf",
        "type": "comment",
        "z": "46cfc3b5.ec68cc",
        "name": "连接到下面的点是图片通道,不是返回值",
        "info": "",
        "x": 1060,
        "y": 520,
        "wires": []
    },
    {
        "id": "5615b242.afd1ec",
        "type": "time-range-switch",
        "z": "46cfc3b5.ec68cc",
        "name": "时间范围",
        "lat": "30.917265839216284",
        "lon": "120.07766738374926",
        "startTime": "22:00",
        "endTime": "07:00",
        "startOffset": 0,
        "endOffset": 0,
        "x": 1960,
        "y": 420,
        "wires": [
            [],
            [
                "10fac6cd.0d5779"
            ]
        ]
    },
    {
        "id": "33e78dfc.6de672",
        "type": "function",
        "z": "46cfc3b5.ec68cc",
        "name": "人数检测为零检查次数",
        "func": "flow.set('count', 2);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 340,
        "y": 540,
        "wires": [
            [
                "87d4737f.de24d"
            ]
        ]
    },
    {
        "id": "ec6459c0.e12648",
        "type": "function",
        "z": "46cfc3b5.ec68cc",
        "name": "检查次数减1",
        "func": "var count = flow.get('count')||0;\nif(count>0){\n    count = count-1;\n    flow.set('count', count);\n}\nmsg.payload = count;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 1530,
        "y": 260,
        "wires": [
            [
                "c20e7912.628898"
            ]
        ]
    },
    {
        "id": "c20e7912.628898",
        "type": "switch",
        "z": "46cfc3b5.ec68cc",
        "name": "判断检查次数是否为零",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "0",
                "vt": "str"
            },
            {
                "t": "gt",
                "v": "0",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 1580,
        "y": 60,
        "wires": [
            [
                "ef751980.148608",
                "5615b242.afd1ec"
            ],
            [
                "87d4737f.de24d"
            ]
        ]
    }
]



回复

使用道具 举报

2

主题

68

帖子

734

积分

高级会员

Rank: 4

积分
734
金钱
666
HASS币
10
发表于 2020-3-6 16:01:19 | 显示全部楼层
可以考虑加个人体传感器,不过目前的人体传感器很多都是被动式的,静止不动的话就检测不到
回复

使用道具 举报

4

主题

341

帖子

3422

积分

论坛元老

Rank: 8Rank: 8

积分
3422
金钱
3081
HASS币
0
发表于 2020-3-6 16:02:53 | 显示全部楼层
这个时候就需要一个人体传感器了!
回复

使用道具 举报

46

主题

641

帖子

4411

积分

元老级技术达人

积分
4411
金钱
3740
HASS币
120
 楼主| 发表于 2020-3-6 16:42:32 来自手机 | 显示全部楼层
用人体传感器的话,要配置等待一段时间没检测到人体活动后关灯,否则很容易误关。这样感觉不太完美,人都进来了,灯还亮着
回复

使用道具 举报

46

主题

641

帖子

4411

积分

元老级技术达人

积分
4411
金钱
3740
HASS币
120
 楼主| 发表于 2020-3-6 16:48:16 来自手机 | 显示全部楼层
菲麦物联 发表于 2020-3-6 16:01
可以考虑加个人体传感器,不过目前的人体传感器很多都是被动式的,静止不动的话就检测不到 ...

加个人体传感器,位置选得好一点,延时关闭配置长一点,可以做到几乎不误关。就是会觉得有点不完美,有时候人进来,接受不了灯还亮着就手动关一下,那天自动化就当保底了,至少忘关了也不会一直开着。
回复

使用道具 举报

2

主题

68

帖子

734

积分

高级会员

Rank: 4

积分
734
金钱
666
HASS币
10
发表于 2020-3-6 17:14:00 | 显示全部楼层
evantalk 发表于 2020-3-6 16:48
加个人体传感器,位置选得好一点,延时关闭配置长一点,可以做到几乎不误关。就是会觉得有点不完美,有时 ...

其实延时这种做法也是有好处的,可以避免传感器处于临界状态时灯频繁开关
回复

使用道具 举报

175

主题

2967

帖子

7606

积分

超级版主

我就是六神

Rank: 8Rank: 8

积分
7606
金钱
4614
HASS币
398

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

QQ
发表于 2020-3-6 17:44:41 | 显示全部楼层
笑而不语,
回复

使用道具 举报

30

主题

493

帖子

4795

积分

论坛元老

佑桑

Rank: 8Rank: 8

积分
4795
金钱
4287
HASS币
156

教程狂人

发表于 2020-3-6 22:08:39 | 显示全部楼层
我家要進入後陽台前需經過廚房
所以設計為人體感應只負責開燈, 廚房燈關閉時一併關後陽台燈
ASRock H370 PRO4, 48GB, 8TBx3 + 2TBx3
ESXi 6.7 + Ununtu + Docker + HASS.IO -> Homeassistant OS
(Home Assistant Supervised 官方文件)
回复

使用道具 举报

46

主题

641

帖子

4411

积分

元老级技术达人

积分
4411
金钱
3740
HASS币
120
 楼主| 发表于 2020-3-6 22:13:05 | 显示全部楼层
chinyaolin 发表于 2020-3-6 22:08
我家要進入後陽台前需經過廚房
所以設計為人體感應只負責開燈, 廚房燈關閉時一併關後陽台燈 ...

也是一个不错的思路
回复

使用道具 举报

40

主题

3056

帖子

1万

积分

超级版主

Nero

Rank: 8Rank: 8

积分
11149
金钱
8042
HASS币
182
发表于 2020-3-7 08:40:45 | 显示全部楼层

版主你好坏啊 还笑而不语。

我也笑而不语
Nero
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-25 03:41 , Processed in 0.069643 second(s), 36 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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