找回密码
 立即注册

微信扫码登录

搜索
楼主: arnold3115

[流程系列] 请教大神如何在function里直接操作设备,不用action节点

[复制链接]

3

主题

42

回帖

430

积分

中级会员

积分
430
金钱
385
HASS币
0
发表于 昨天 19:48 | 显示全部楼层
function函数后面必须要接action,但是相关的配置可以写到function里面去,action留空。
[
    {
        "id": "8e568f317f8c4fce",
        "type": "function",
        "z": "2310c5557080bf9b",
        "name": "1",
        "func": "msg.payload = {\n    domain: \"switch\",\n    service: \"turn_on\",\n    target: {\n        entity_id: \"switch.lemesh_cn_1095285407_sw8a01_on_p_2_1\"\n    }\n};\nreturn msg;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 470,
        "y": 620,
        "wires": [
            [
                "dec41619bc902f05",
                "87544d5151b489b6"
            ]
        ]
    },
    {
        "id": "aebef9e3578df98c",
        "type": "inject",
        "z": "2310c5557080bf9b",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 380,
        "y": 620,
        "wires": [
            [
                "8e568f317f8c4fce"
            ]
        ]
    },
    {
        "id": "87544d5151b489b6",
        "type": "api-call-service",
        "z": "2310c5557080bf9b",
        "name": "",
        "server": "055cd11075a00c23",
        "version": 7,
        "debugenabled": false,
        "action": "",
        "floorId": [],
        "areaId": [],
        "deviceId": [],
        "entityId": [],
        "labelId": [],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "blockInputOverrides": false,
        "domain": "",
        "service": "",
        "x": 600,
        "y": 620,
        "wires": [
            []
        ]
    },
    {
        "id": "055cd11075a00c23",
        "type": "server",
        "name": "Home Assistant",
        "version": 6,
        "addon": false,
        "rejectUnauthorizedCerts": false,
        "ha_boolean": [
            "y",
            "yes",
            "true",
            "on",
            "home",
            "open"
        ],
        "connectionDelay": true,
        "cacheJson": true,
        "heartbeat": false,
        "heartbeatInterval": 30,
        "areaSelector": "friendlyName",
        "deviceSelector": "friendlyName",
        "entitySelector": "friendlyName",
        "statusSeparator": ": ",
        "statusYear": "hidden",
        "statusMonth": "short",
        "statusDay": "numeric",
        "statusHourCycle": "default",
        "statusTimeFormat": "h:m",
        "enableGlobalContextStore": true
    },
    {
        "id": "cb0e148dfbdef24c",
        "type": "global-config",
        "env": [],
        "modules": {
            "node-red-contrib-home-assistant-websocket": "0.80.3"
        }
    }
]
回复

使用道具 举报

3

主题

42

回帖

430

积分

中级会员

积分
430
金钱
385
HASS币
0
发表于 昨天 19:50 | 显示全部楼层
tangyuan 发表于 2025-12-4 19:48
function函数后面必须要接action,但是相关的配置可以写到function里面去,action留空。
[
    {

action节点中的Block input overrides选项不要勾选
回复

使用道具 举报

3

主题

42

回帖

430

积分

中级会员

积分
430
金钱
385
HASS币
0
发表于 昨天 19:51 | 显示全部楼层
a784174467 发表于 2025-11-21 10:53
请问怎么直接用用function直接获取到设备的状态呀?能分享下代码嘛!非常感谢 ...
[
    {
        "id": "f426d8c79e075310",
        "type": "function",
        "z": "2310c5557080bf9b",
        "name": "function 8",
        "func": "let entity_id = "binary_sensor.linp_cn_1084414517_hb01_occupancy_status_p_2_1";\nlet ha = global.get("homeassistant") || {};\nlet states = ha["homeAssistant"] ? ha["homeAssistant"].states : {};\n\nmsg.payload = states[entity_id]?.state ?? "unknown";\nreturn msg;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 300,
        "y": 460,
        "wires": [
            [
                "cecc85d171455a82"
            ]
        ]
    },
    {
        "id": "fb77063a103372d0",
        "type": "inject",
        "z": "2310c5557080bf9b",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 130,
        "y": 460,
        "wires": [
            [
                "f426d8c79e075310"
            ]
        ]
    },
    {
        "id": "cecc85d171455a82",
        "type": "debug",
        "z": "2310c5557080bf9b",
        "name": "debug 16",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 480,
        "y": 460,
        "wires": []
    }
]

回复

使用道具 举报

3

主题

42

回帖

430

积分

中级会员

积分
430
金钱
385
HASS币
0
发表于 昨天 19:52 | 显示全部楼层

要在server节点中开启全局上下文存储
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian ( 晋ICP备17001384号-1 )

GMT+8, 2025-12-5 05:07 , Processed in 0.367596 second(s), 10 queries , MemCached On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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