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

 找回密码
 立即注册
查看: 437|回复: 1

[流程系列] 这几天刚接触ha一直使用自动化,万万没想到RED这么牛

[复制链接]

1

主题

4

帖子

36

积分

新手上路

Rank: 1

积分
36
金钱
32
HASS币
0
发表于 2024-7-27 12:01:05 | 显示全部楼层 |阅读模式
本帖最后由 crsnoo32 于 2024-7-27 12:07 编辑

第一次搞可能流程比较简单将就着看,以下是所用代码(微信发送功能使用了微信HOOK搭建了WS以及http服务)
WS服务主要监听微信消息并执行相关设备(服务已构建还未完成)
HTTP请求用于发送执行设备状态
整体流程】:实现有效期判断执行设备,并将设备执行状态发送至微信
dffb265ff28e8f92826bd711d68375a.png
c2318ee9ef8b8660788ef62f3489b40.png
[{
<font _mstmutation="1" _msttexthash="4098767581519" _msthash="140">“id”: “02844765b73484d9”,
 “type”: “开关”,
 “z”: “539a443303054cbd”,
 “name”: “湿度”,
 “property”: “payload”,
 “propertyType”: “msg”,
 “rules”: [{
 “t”: “lte”,
 “v”: “55”,
 “vt”: “str”
 }, {
 “t”: “gte”,
 “v”: “56”,
 “vt”: “str”
 }],
 “checkall”: “true”,
 “repair”: false,
 “outputs”: 2,
“x”: 770,
 “y”: 540,
 “wires”: [
 [“ad041d98ca462275”],
 [“79514ab01b0c8835”]
 ]
}, {
 “id”: “e9245757a6773487”,
 “type”: “api-call-service”,
 “z”: “539a443303054cbd”,
 “name”: “主卧关闭加湿器”,
 “server”: “e81eee80.f09d8”,
 “version”: 5,
 “debugenabled”: true,
 “domain”: “switch”,
 “service”: “turn_off“,
 ”areaId“: [],
 ”deviceId“: [”d60f8dd9b198d852057e880e98b099b4“],
 ”entityId“: [],
 ”data“: ”“,
 ”dataType“: ”jsonata“,
 ”mergeContext“: ”“,
 ”mustacheAltTags“: false,
 ”outputProperties“: [],
 ”queue“: ”none“,
 ”x“: 1240, ”y“: 580,

 ”wires“: [
 []
 ]
}, {
 ”id“: ”14c556d0a42e65ba“,
 “type”: “api-call-service”,
 “z”: “539a443303054cbd”,
 “name”: “主卧打开加湿器”,
 “server”: “e81eee80.f09d8”,
 “version”: 5,
 “debugenabled”: true,
 “domain”: “switch”,
 “service”: “turn_on”,
 “areaId”: [], “deviceId”: [],
 “deviceId”: [“d60f8dd9b198d852057e880e98b099b4”],
 “entityId”: “],
 ”data“: ”“,
 ”dataType“: ”jsonata“,
 ”mergeContext“: ”“,
 ”mustacheAltTags“: false,
 ”outputProperties“: [],
 ”queue“: ”none“,
 ”x“: 1240,
 ”y“: 480,
 ”wires“: [
 []
 ]
}, {
 ”id“: ”ad041d98ca462275“,
 ”type“: ”api-current-state“,
 ”z“: ”539a443303054cbd“,
 ”name“: ”加湿器是关“,
 ”server“: ”e81eee80.f09d8“,
 ”version“: 3,
 ”outputs“: 2,
 ”halt_if“: ”off“,
 ”halt_if_type“: ”str“,
 ”halt_if_compare“: ”is“,
 ”entity_id“: ”switch.0xa4c1389baa04c246“,
 ”state_type“: ”str“,
 ”blockInputOverrides“: false,
 ”outputProperties“: [{
 ”property“: ”payload“,
 ”propertyType“: ”msg“,
 ”value“: ”{\“botid\”:\“wxid_567656512\”,\“chatid\”:\“wxid_d4ri0tb6w212\”,\“content\”:\“【加湿器已打开】\”,\”supplementAtName\“:true}”,
 “valueType”: “str”
 }, {
 “property”: “data”,
 “propertyType”: “msg”,
 “value”: “”,
 “valueType”: “entity”
 }],
 “for”: “0”,
 “forType”: “num”,
 “forUnits”: “分钟”,
 “override_topic”: false,
 “state_location”: “payload”,
 “override_payload”: “msg”,
 “entity_location”: ”data“,
 ”override_data“: ”msg“,
 ”x“: 950,
 ”y“: 480,
 ”wires“: [
 [”14c556d0a42e65ba“, ”1a2b3c4d5e6f7g8h“],
 []
 ]
}, {
 ”id“: ”79514ab01b0c8835“,
 ”type“: ”api-current-state“,
 ”z“: ”539a443303054cbd“,
 ”name“: ”加湿器是开“,
 ”server“: ”e81eee80.f09d8“,
 ”version“: 3,
 ”outputs“: 2,
 ”halt_if“: ”on“,
 ”halt_if_type“: ”str“,
 ”halt_if_compare“: ”is“,
 ”entity_id“: ”switch.0xa4c1389baa04c246“,
 ”state_type“: ”str“,
 ”blockInputOverrides“: false,
 ”outputProperties“: [{
 ”property“: ”payload“,
 ”propertyType“: ”msg“,
 ”value“: ”{\“botid\”:\“wxid_56765065212\”,\“chatid\”:\“wxid_d4rl6w212\”,\“content\”:\“【加湿器已关闭】\”,\“supplementAtName\”:true}“,
 ”valueType“: ”str“
 }, {
 ”property“: ”data“,
 ”propertyType“: ”msg“,
 ”value“: ”“,
 ”valueType“: ”entity“
 }],
 ”for“: ”0“,
 ”forType“: ”num“,
 ”forUnits“: ”分钟“,
 ”override_topic“: false,
 ”state_location“: ”payload“,
 ”override_payload“: ”msg“,
 ”entity_location“: ”data“,
 ”override_data“: ”msg“,
 ”x“: 950,
 ”y“: 580,
 ”wires“: [
”e9245757a6773487“],
 [”1a2b3c4d5e6f7g8h“]
 ]
}, {
 ”id“: ”69fdae5e484b8b63“,
 ”type“: ”switch“,
 ”z“: ”539a443303054cbd“,
 ”name“: ”温度“,
 ”property“: ”payload“,
 ”propertyType“: ”msg“,
 ”rules“: [{
 ”t“: ”gte“,
 ”v“: ”28“,
 ”vt“: ”str“
 }, {
 “t”: “LTE”,
 “v”: “26.5”,
 “vt”: “str”
 }],
 “checkall”: “真”,
 “repair”: 假,
 “outputs”: 2,
 “x”: 770,
 “y”: 780,
 “wires”: [
 [“4315e2e20aaf28ad”],
 [“742fc78d9c7fac73”]
 ]
}, {
 “id”: “4315e2e20aaf28ad”,
 “type”: “api-current-state”,
 “z“: ”539a443303054cbd“,
 ”name“: ”空调是关“,
 ”server“: ”e81eee80.f09d8“,
 ”version“: 3,
 ”outputs“: 2,
 ”halt_if“: ”off“,
 ”halt_if_type“: ”str“,
 ”halt_if_compare“: ”is“,
 ”entity_id“: ”climate.lumi_mcn02_6612_air_conditioner“,
 ”state_type“: ”str“,
 ”blockInputOverrides“: false,
 ”outputProperties“: [{
 ”property“: ”payload“,
 ”propertyType“: ”msg“,
 ”value“: ”{\“botid\”:\“wxid_5676565212\”,\“chatid\”:\“wxid_d4rltb6w212\”,\“content\”:\“【空调已打开】\”,\“supplementAtName\”:true}“,
 ”valueType“: ”str“
 }, {
 ”property“: ”data“,
 ”propertyType“: ”msg“,
 ”value“: ”“,
 ”valueType“: ”entity“
 }],
 ”for“: ”0“,
 ”forType“: ”num“,
 “forUnits”: “分钟”,
 “override_topic”: false,
 “state_location”: “payload”,
 “override_payload”: “msg”,
 “entity_location“: ”data“,
 ”override_data“: ”msg“,
 ”x“: 940,
 ”y“: 720,
 ”wires“: [
 [”e48064a9642a1346“, ”1a2b3c4d5e6f7g8h“],
 []
 ]
}, {
 ”id“: ”742fc78d9c7fac73“,
 ”type“: ”api-current-state“,
 ”z“: ”539a443303054cbd“,
 ”name“: ”空调是开“,
 ”server“: ”e81eee80.f09d8“,
 ”version“: 3,
“outputs”: 2,
 “halt_if”: “cool”,
 “halt_if_type”: “str”,
 “halt_if_compare”: “is”,
 “entity_id”: “climate.lumi_mcn02_6612_air_conditioner”,
 “state_type”: “str”,
 “blockInputOverrides”: false,
 “outputProperties”: [{
 “property”: “payload”,
 “propertyType”: “msg”,
“value”: “{\”botid\“:\”wxid_56767212\“,\”chatid\“:\”wxid_d4rl36w212\“,\”content\“:\”【加湿器已关闭】\“,\”supplementAtName\“:true}”,
 “valueType”: “str”
 }, {
 “property”: “data”,
 “propertyType”: “msg”,
 “value”: “value”: “”,
 “valueType”: “entity”
 }],
 “for”: “0”,
 “forType”: “num”,
 “forUnits”: “分钟”,
 “override_topic”: false,
 “state_location”: “有效载荷”,
 “override_payload”: “消息”,
 “entity_location”: “数据”,
 “override_data”: “消息”,
 “x”: 940,
 “y”: 820,
 “wires”: [
 [“9a1e202aa091268b”, “1a2b3c4d5e6f7g8h”],
 []
 ]
}, {
 “id”: “e48064a9642a1346”,
 “type”: “api-call-service”,
 “z”: ”539a443303054cbd“,
 ”name“: ”主卧打开空调“,
 ”server“: ”e81eee80.f09d8“,
 ”version“: 5,
 ”debugenabled“: true,
 ”domain“: ”climate“,
 ”service“: ”set_temperature“,
 ”areaId“: [],
 ”deviceId“: [],
 ”entityId“: [”climate.lumi_mcn02_6612_air_conditioner“],
 ”data“: ”{\“temperature\”:20}“,
 ”dataType“: ”json“,
 ”mergeContext“: ”“,
 ”mustacheAltTags“: false,
 ”outputProperties“: [],
 ”queue“: ”none“,
 ”x“: 1240,
 ”y“: 720,
 ”wires“: [
 []
 ]
}, {
 ”id“: ”9a1e202aa091268b“,
 ”type“: ”api-call-service“,
 ”z“: ”539a443303054cbd“,
 ”name“: ”主卧关闭空调“,
 ”server“: ”e81eee80.f09d8“,
“version”: 5,
 “debugenabled”: true,
 “domain”: “climate”,
 “service”: “turn_off”,
 “areaId”: [],
 “deviceId”: [],
 “entityId”: [“climate.lumi_mcn02_6612_air_conditioner”],
 “data”: “{\”temperature\“:20}”,
 “dataType”: “json”,
 “mergeContext”: “”,
 “mustacheAltTags”: false,
 “outputProperties”: [],
 ”queue“: ”none“,
 ”x“: 1240,
 ”y“: 820,
 ”wires“: [
 []
 ]
}, {
 ”id“: ”5fbbbb6b9a96334e“,
 ”type“: ”function“,
 ”z“: ”539a443303054cbd“,
 ”name“: ”设置有效期时间“,
 ”func“: ”var now = new Date();\nvar hour = now.getHours();\n\nif ((0 <= hour && hour <= 7) ||(10 <= 小时 && 小时 <= 17)){\n msg.payload = \“有效\”;\n} else {\n msg.payload = \“无效\”;\n}\nreturn msg;“,
 ”outputs“: 1,
 ”timeout“: 0,
 ”noerr“: 0,
 ”initialize“: ”“,
 ”finalize“: ”“,
 ”libs“: [],
 ”x“: 276,
 ”y“: 660,
 ”wires“: [
 [”a11d10cc09fcfa8f“]
 ]
}, {
 ”id“: ”be15798c5e1e565c“,
 ”type“: ”注入“,
“z”: “539a443303054cbd”,
 “name”: “”,
 “props”: [{
 “p”: “payload”
 }, {
 “p”: “topic”,
 “vt”: “str”
 }],
 “repeat”: “1”,
 “crontab”: “”,
 “once”: true,
 “onceDelay”: 0.1,
 “topic”: “”,
 “payload”: “”,
 “payloadType”: “date”,
 “x”: 160,
 “y”: 660,
“wires”: [
 [“5fbbbb6b9a96334e”]
 ]
}, {
 “id”: “a11d10cc09fcfa8f”,
 “type”: “switch”,
 “z”: “539a443303054cbd”,
 “name”: “时间返回数据判断”,
 “property”: “payload”,
 “propertyType”: “msg”,
 “rules”: [{
 “t”: “eq”,
 “v”: “有效”,
 “vt”: “str”
 }],
 “checkall”: “true”,
“repair”: false,
 “outputs”: 1,
 “x”: 430,
 “y”: 660,
 “wires”: [
 [“0463f714ae4e1e87”, “4d6bf45f97b3c4bc”]
 ]
}, {
 “id”: “0463f714ae4e1e87”,
 “type”: “api-current-state”,
 “z”: “539a443303054cbd”,
 “name”: “主卧温度”,
 “server”: “e81eee80.f09d8”,
 “version”: 3,
 “outputs”: 1,
“halt_if”: “”,
 “halt_if_type”: “str”,
 “halt_if_compare”: “is”,
 “entity_id”: “sensor.atc_zwwd_7436_temperature”,
 “state_type”: “str”,
 “blockInputOverrides”: false,
 “outputProperties”: [{
 “property”: “payload”,
 “propertyType”: “msg”,
 “value”: “”,
 “valueType”: “entityState”
 }, {
 “property”: “data”,
 “propertyType”: “msg”,
 “value”: “”,
 “valueType”: “entity”
 }, {
 “property”: “topic”,
 “propertyType”: “msg”,
 “value”: “”,
 “valueType”: “triggerId”
 }],
 “for”: “0”,
 “forType”: “num”,
 “forUnits”: “分钟”,
 “override_topic”: false,
 “state_location”: “有效载荷”,
“override_payload”: “msg”,
 “entity_location”: “data”,
 “override_data”: “msg”,
 “x”: 600,
 “y”: 780,
 “wires”: [
 [“69fdae5e484b8b63”]
 ]
}, {
 “id”: “4d6bf45f97b3c4bc”,
 “type”: “api-current-state”,
 “z”: “539a443303054cbd”,
 “name”: “主卧湿度”,
 “server”: “e81eee80.f09d8”,
 “version”: 3,
 “outputs”: 1,
 “halt_if”: “”,
 “halt_if_type”: “str”,
 “halt_if_compare”: “is”,
 “entity_id”: “sensor.atc_zwwd_7436_humidity”,
 “state_type”: “str”,
 “blockInputOverrides”: false,
 “outputProperties”: [{
 “property”: “payload”,
 ”propertyType“: ”msg“,
 ”value“: ”“,
 ”valueType“: ”entityState“
 }, {
 ”property“: ”data“,
 ”propertyType“: ”msg“,
 ”value“: ”“,
 ”valueType“: ”entity“
 }, {
 ”property“: ”topic“,
 ”propertyType“: ”msg“,
 ”value“: ”“,
 ”valueType“: ”triggerId“
 }],
 ”for“: ”0“,
 ”forType“: ”num“,
 ”forUnits“: ”分钟“,
 ”override_topic“: false,
 ”state_location“: ”payload“,
 ”override_payload“: ”msg“,
 ”entity_location“: ”data“,
 ”override_data“: ”msg“,
 ”x“: 600,
 ”y“: 540,
 ”wires“: [
 [”02844765b73484d9“]
 ]
}, {
 ”id“: ”1a2b3c4d5e6f7g8h“,
 ”type“: ”HTTP request“,
 ”z“: ”539a443303054cbd“,
 ”name“: ”微信发送设备执行状态“,
 ”method“: ”POST“,
 ”ret“: ”txt“,
 ”paytoqs“: ”ignore“,
 ”url“: ”http://192.168.2.88:8070/sendTextMessage“,
 ”tls“: ”“,
 ”persist“: false,
 ”proxy“: ”“,
 ”insecureHTTPParser“: false,
 ”authType“: ”“,
 ”senderr“: false,
 ”headers“:[{
 “keyType”: “内容类型”,
 “keyValue”: “”,
 “valueType”: “other”,
 “valueValue”: “application/json”
 }],
 “x”: 1260,
 “y”: 660,
 “wires”: [
 []
 ]
}, {
 “id”: “e81eee80.f09d8”,
 “type”: “服务器”,
 “name”: “家庭助理”,
 “addon”: 真,
“rejectUnauthorizedCerts”: 真,
 “ha_boolean”: “”,
 “connectionDelay”: false,
 “cacheJson”: false,
 “heartbeatInterval
”: “”,
 “statusSeparator”: “”,
 “enableGlobalContextStore”: false</font>
}]










回复

使用道具 举报

0

主题

13

帖子

57

积分

注册会员

Rank: 2

积分
57
金钱
44
HASS币
0
发表于 2024-7-27 13:09:32 | 显示全部楼层



/**
* Linux常用命令:rsync -rogpav --delete /home /tmp 同步两边的目录
* 不是别人,是我,承认了你的价值
* Link https://greasyfork.org/zh-CN/scripts/396933-hostloc-zsbd
*/
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-9-8 09:16 , Processed in 0.054458 second(s), 27 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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