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

 找回密码
 立即注册
查看: 10641|回复: 4

[教程系列] 【Node-red】分享一个判断节假日的流程

[复制链接]

13

主题

127

帖子

1016

积分

金牌会员

Rank: 6Rank: 6

积分
1016
金钱
889
HASS币
0
发表于 2021-6-19 14:51:24 | 显示全部楼层 |阅读模式
本帖最后由 gmmy1979 于 2021-11-27 13:06 编辑

2021-11-27更新:flow里面的api有问题,会出现GET不能返回值的情况,论坛有朋友提供一个免费的api(https://timor.tech/api/holiday)及其他实现方式(https://bbs.hassbian.com/thread-14648-1-1.html),具体使用方式请参考网站文档。
------------------------------------------------分割线

前提:本人也是小白,刚入门,不断在论坛中爬坑,与大家共同进步。望大佬勿喷。弄这个流程的初衷:自己在nodered里面设置了周一至周五起床唤醒:小爱TTS,然后随机播放音乐。如果工作日还好,但遇到节假日是周1至周5的情况,就不想触发。当初想通过论坛里面的那个节假日的插件(链接:https://bbs.hassbian.com/thread-9133-1-1.html),不知道是不是插件失效,我是没用不起,所有通这个来判断节假日。
1、homeassistant yaml添加
sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
2、api地址及调用方法
https://www.kancloud.cn/xiaoggvip/holiday_free/1606802

3、Node-red如下,附件
[{"id":"b9f8a296.ccf49","type":"inject","z":"8b8a8d71.0b763","name":"03文本图片","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"30 09 * * 5","once":false,"onceDelay":"2","topic":"","payload":"{}","payloadType":"json","x":150,"y":280,"wires":[["f67b000b.020bb"]]},{"id":"a0146257.383f4","type":"http request","z":"8b8a8d71.0b763","name":"GET请求","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://tool.bitefu.net/jiari/?d={{{payload}}}&info=1","tls":"","persist":false,"proxy":"","authType":"","x":640,"y":280,"wires":[["53135896.ac15b8"]]},{"id":"53135896.ac15b8","type":"function","z":"8b8a8d71.0b763","name":"判断","func":"//声明新的变量date=msg.payload(上个节点的值)。\n//date.type为上个节点msg.payload.type的值。\nvar date=msg.payload \nif (date.type==0)  \n{\n    msg.payload = "工作日"\n}\nelse if (date.type==1)\n{\n    msg.payload = "周末"\n}\nelse if (date.type==2)\n{\n    msg.payload = "节假日"\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":790,"y":280,"wires":[["99cdcdae.d30e9"]]},{"id":"f67b000b.020bb","type":"api-current-state","z":"8b8a8d71.0b763","name":"获取日期","server":"43ab5baf.650144","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.date","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":320,"y":280,"wires":[["97b93866.0aaba8"]]},{"id":"97b93866.0aaba8","type":"change","z":"8b8a8d71.0b763","name":"修改格式","rules":[{"t":"change","p":"payload","pt":"msg","from":"-","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":280,"wires":[["a0146257.383f4"]]},{"id":"14ba1d05.6dc9f3","type":"link out","z":"8b8a8d71.0b763","name":"","links":["b9e8b389.12553"],"x":1035,"y":280,"wires":[]},{"id":"99cdcdae.d30e9","type":"switch","z":"8b8a8d71.0b763","name":"工作日","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"工作日","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":930,"y":280,"wires":[["14ba1d05.6dc9f3"]]},{"id":"43ab5baf.650144","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

flows.rar

1.24 KB, 下载次数: 157

回复

使用道具 举报

22

主题

184

帖子

2536

积分

论坛DIY达人

积分
2536
金钱
2347
HASS币
30
发表于 2021-6-19 20:44:36 | 显示全部楼层
NR只有时间戳,是不是没有导入全?
回复

使用道具 举报

13

主题

127

帖子

1016

积分

金牌会员

Rank: 6Rank: 6

积分
1016
金钱
889
HASS币
0
 楼主| 发表于 2021-6-20 21:44:19 | 显示全部楼层
innx 发表于 2021-6-19 20:44
NR只有时间戳,是不是没有导入全?

弄错了,重新上传了附件。
回复

使用道具 举报

20

主题

334

帖子

2495

积分

论坛积极会员

积分
2495
金钱
2161
HASS币
0
发表于 2021-9-22 12:07:15 | 显示全部楼层
顶一个,一直在找这个接口
回复

使用道具 举报

0

主题

29

帖子

147

积分

注册会员

Rank: 2

积分
147
金钱
118
HASS币
0
发表于 2023-7-28 16:16:04 | 显示全部楼层
现在还能用么
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-12-22 22:35 , Processed in 0.077476 second(s), 29 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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