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

 找回密码
 立即注册
查看: 378|回复: 2

[流程系列] 判断是否节假日并持久化

[复制链接]

5

主题

43

帖子

253

积分

中级会员

Rank: 3Rank: 3

积分
253
金钱
210
HASS币
0
发表于 2024-2-19 15:38:46 | 显示全部楼层 |阅读模式
简单来说流程如下1. 调用api
2. 写入HA的辅助元素


1. https://www.tianapi.com/apiview/139 注册个开发者账号申请下api 获取token key(100次调用/天,够用)
2. ha中新增个虚拟开关
20240219153249.jpg


3.导入流程
[
    {
        "id": "c47395601e1189fd",
        "type": "inject",
        "z": "18f3d6ef71710367",
        "name": "每天早上00:01",
        "props": [
            {
                "p": "token",
                "v": "YOUR_TOKEN_KEY",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "01 00 * * *",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 180,
        "y": 400,
        "wires": [
            [
                "8974b6d77d75f52a"
            ]
        ]
    },
    {
        "id": "8974b6d77d75f52a",
        "type": "function",
        "z": "18f3d6ef71710367",
        "name": "获取当前日期",
        "func": "// Function节点中的代码\nlet token = msg.token;\nlet now = new Date();\nlet year = now.getFullYear();\nlet month = ("0" + (now.getMonth() + 1)).slice(-2); // 加1因为月份是从0开始的\nlet day = ("0" + now.getDate()).slice(-2);\nlet formattedDate = year + "-" + month + "-" + day;\n\nmsg.url = `https://apis.tianapi.com/jiejiari/index?key=${token}&type=0&date=${formattedDate}`;\n\nmsg.payload = formattedDate;\nreturn msg;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 420,
        "y": 420,
        "wires": [
            [
                "337cbee97c05d3e9"
            ]
        ]
    },
    {
        "id": "337cbee97c05d3e9",
        "type": "http request",
        "z": "18f3d6ef71710367",
        "name": "今天是否是节假日",
        "method": "GET",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 630,
        "y": 440,
        "wires": [
            [
                "2f90222899418958"
            ]
        ]
    },
    {
        "id": "2f90222899418958",
        "type": "switch",
        "z": "18f3d6ef71710367",
        "name": "需要上班",
        "property": "payload.result.list[0].isnotwork",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "0",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "1",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 860,
        "y": 460,
        "wires": [
            [
                "ea836bd9da07fa1e"
            ],
            [
                "6485aea7e97c015c"
            ]
        ]
    },
    {
        "id": "ea836bd9da07fa1e",
        "type": "api-call-service",
        "z": "18f3d6ef71710367",
        "name": "需要上班",
        "server": "69621d87.7af904",
        "version": 5,
        "debugenabled": false,
        "domain": "input_boolean",
        "service": "turn_on",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "input_boolean.ying_gai_shang_ban"
        ],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 1040,
        "y": 460,
        "wires": [
            []
        ]
    },
    {
        "id": "6485aea7e97c015c",
        "type": "api-call-service",
        "z": "18f3d6ef71710367",
        "name": "不需要上班",
        "server": "69621d87.7af904",
        "version": 5,
        "debugenabled": false,
        "domain": "input_boolean",
        "service": "turn_on",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "input_boolean.ying_gai_shang_ban"
        ],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 1050,
        "y": 520,
        "wires": [
            []
        ]
    },
    {
        "id": "69621d87.7af904",
        "type": "server",
        "name": "HA",
        "addon": false,
        "rejectUnauthorizedCerts": false,
        "ha_boolean": "y|yes|true|on|home|open|工作日",
        "connectionDelay": true,
        "cacheJson": false,
        "heartbeat": true,
        "heartbeatInterval": "30",
        "areaSelector": "id",
        "deviceSelector": "id",
        "entitySelector": "id",
        "statusSeparator": "",
        "statusYear": "2-digit",
        "statusMonth": "2-digit",
        "statusDay": "2-digit",
        "statusHourCycle": "h23",
        "statusTimeFormat": "h:m:s",
        "enableGlobalContextStore": false
    }
]
4. 修改第一步中的TOKEN为你自己的, 修改HA配置。搞定

5. 要用时直接获取entity状态判断是否需要上班
20240219153755.jpg



回复

使用道具 举报

6

主题

738

帖子

5594

积分

论坛元老

Rank: 8Rank: 8

积分
5594
金钱
4851
HASS币
20
发表于 2024-2-19 18:06:32 | 显示全部楼层
直接用sensor里rest会更好一些
https://www.home-assistant.io/integrations/sensor.rest/
回复

使用道具 举报

5

主题

43

帖子

253

积分

中级会员

Rank: 3Rank: 3

积分
253
金钱
210
HASS币
0
 楼主| 发表于 2024-2-20 20:15:20 | 显示全部楼层
mitu 发表于 2024-2-19 18:06
直接用sensor里rest会更好一些
https://www.home-assistant.io/integrations/sensor.rest/

还不是很习惯用ha,所以流程都丢nodered里的
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-4-29 16:51 , Processed in 0.397686 second(s), 27 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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