找回密码
 立即注册

微信扫码登录

搜索
楼主: relliky

[修仙教程] 【设备多怎么办】以房间为单位写易维护的配置代码

 火.. [复制链接]

8

主题

863

回帖

5240

积分

论坛元老

积分
5240
金钱
4369
HASS币
0
发表于 2023-4-9 19:44:36 | 显示全部楼层
厉害,谢谢分享,mark
回复

使用道具 举报

21

主题

120

回帖

966

积分

高级会员

积分
966
金钱
825
HASS币
0
发表于 2023-4-10 22:04:23 | 显示全部楼层
如何写配置教程
回复

使用道具 举报

1

主题

13

回帖

1587

积分

金牌会员

积分
1587
金钱
1573
HASS币
0
发表于 2023-4-11 11:18:45 | 显示全部楼层
不明觉厉!!
回复

使用道具 举报

33

主题

1115

回帖

5488

积分

论坛元老

积分
5488
金钱
4325
HASS币
90
 楼主| 发表于 2023-4-11 17:29:40 | 显示全部楼层
W@LTER 发表于 2023-4-4 17:15
有人做小白教程吗? 没想到怎么用

不好意思,现阶段我只能做到功能展示。我还没有完善到可以有使用教程的地步。等明年我应该可以做到有配置教程了

我家全屋智能的HA设置 https://github.com/relliky/Tais_Home_Assistant_Config
回复

使用道具 举报

wjx 手机认证

0

主题

44

回帖

239

积分

中级会员

积分
239
金钱
195
HASS币
0
发表于 2023-4-13 21:51:24 | 显示全部楼层
学习一下
回复

使用道具 举报

19

主题

700

回帖

4198

积分

元老级技术达人

积分
4198
金钱
3469
HASS币
60
发表于 2023-4-15 16:30:55 | 显示全部楼层
本帖最后由 houhd 于 2023-4-15 16:39 编辑

大佬妞碧。看到那张自动化的图,我还是NR连连看吧。
回复

使用道具 举报

33

主题

1115

回帖

5488

积分

论坛元老

积分
5488
金钱
4325
HASS币
90
 楼主| 发表于 2023-4-15 17:15:42 | 显示全部楼层
本帖最后由 relliky 于 2023-4-15 17:19 编辑
houhd 发表于 2023-4-15 16:30
大佬妞碧。看到那张自动化的图,我还是NR连连看吧。

因为用的函数,其实每个部分都抽象化了,生成的yaml重复代码很多。python的实际代码都挺简单的。

    self.automations += [{
        "alias" : "ZL-" + self.automation_room_name + "Applies Different Scenes Based on Scene Selections (State Execution)" + "-" + self.room_name,
        "configured": self.cfg_scene,
        "trigger": [
          {
            "platform": "state",
            "entity_id": self.room_scene_ctl,
          }
        ],
        "mode":"restart", # using restart to improve responsiveness of a scene execution
        "action": [
          {
            "choose": [
              self.callSceneServiceIfSelected("All White"),
              self.callSceneServiceIfSelected("Ceiling Light White"),
              self.callSceneServiceIfSelected("Lamp LED White"),
              self.callSceneServiceIfSelected("LED White"),
              self.callSceneServiceIfSelected("Hue"),
              self.callSceneServiceIfSelected("Night Mode"),
              self.callSceneServiceIfSelected("Dark Night Mode"),
              self.callSceneServiceIfSelected("All Off"),
              self.callSceneServiceIfSelected("Lights on in hot sunshine"),
              self.callSceneServiceIfSelected("Lights on when bright outdoor"),
              self.callSceneServiceIfSelected("Lights on when dark outdoor")
            ]
          }
        ]
    }]

callSceneServiceIfSelected 再调用具体的callSceneService的实现。


  def callSceneService(self, scene_name):  
      parallel_enable = True  
      scene_service = []  
      if   scene_name == 'All White':
          scene_service += [self.turn(self.lamps, "on"),
                            self.turn(self.ceiling_lights, "on"),
                            self.turn(self.leds, "on"),
                            self.turn(self.tvs, tv_brightness=3)]
      elif scene_name == 'Ceiling Light White':
          scene_service += [self.turn(self.leds + self.lamps, "off"),
                            self.turn(self.ceiling_lights, "on"),
                            self.turn(self.tvs, tv_brightness=3)]   
      #elif scene_name == 'Ceiling Light White with Curtain Open':
      #    scene_service += [self.turn(self.leds + self.lamps, "off"),
      #                      self.turn(self.ceiling_lights, "on"),
      #                      self.turn(self.tvs, tv_brightness=3),
      #                      self.turn(self.curtains, 'on')]   
      elif scene_name == 'Lamp LED White':
          scene_service += [self.turn(self.ceiling_lights, "off"),
                            self.turn(self.lamps, "on"),
                            self.turn(self.leds, "on"),
                            self.turn(self.tvs, tv_brightness=3)]
      elif scene_name == 'LED White':
          scene_service += [self.turn(self.ceiling_lights, "off"),
                            self.turn(self.lamps, "off"),
                            self.turn(self.leds, "on"),
                            self.turn(self.tvs, tv_brightness=2)]
      elif scene_name == 'Hue': 
          parallel_enable = False
          scene_service += [# turn on lights to let adaptive lighting run
                            self.turn(self.lamps + self.leds, "on"),
                            # overwrite adaptive lighting brightiness and set it to max
                            self.turn(self.lamps + self.leds, "on", light_brightness=100),
                            # apply colours
                            { "service" : "pyscript.set_rgb_light_list",
                              "data": {"light_list": self.lamps + self.ceiling_lights+ self.leds}},
                            self.turn(self.tvs, tv_brightness=2)]
      elif scene_name == 'Night Mode': 
          scene_service += [{ "service": "homeassistant.turn_on",
                              "entity_id": "scene." + self.room_entity + "_night_mode" },
                            self.turn(self.tvs, tv_brightness=2)]
      elif scene_name == 'Dark Night Mode': 
          scene_service += [{ "service": "homeassistant.turn_on",
                              "entity_id": "scene." + self.room_entity + "_dark_night_mode" },
                            self.turn(self.tvs, tv_brightness=1)]
      elif scene_name == 'All Off':
          scene_service += [self.turn(self.ceiling_lights, "off"),
                            self.turn(self.lamps, "off"),
                            self.turn(self.leds, "off")]
      elif scene_name in ['Lights on in hot sunshine',
                          'Lights on when bright outdoor',
                          'Lights on when dark outdoor']:
        
        scene_service += [{"parallel":[
          {"if": self.continueIf(self.ceiling_light_control_when[scene_name], "on"), "then": self.turn(self.ceiling_lights, "on")},
          {"if": self.continueIf(self.lamp_control_when[scene_name]         , "on"), "then": self.turn(self.lamps,          "on")},
          {"if": self.continueIf(self.led_control_when[scene_name]          , "on"), "then": self.turn(self.leds,           "on")},
          {"if": self.continueIf(self.curtain_control_when[scene_name]      , "on"), "then": self.turn(self.curtains,       "on")}
          ]}]

      else:
        raise TypeError( "\n" +\
                         "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" + \
                         "Scene " + scene_name + " is not supported." + "\n" + \
                         "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n")
      


      if parallel_enable == True:
        scene_service = [{"parallel":scene_service}] 
        
      # Convert to a single service/entry instead of a list  
      return self.convertToSingleService(scene_service, alias=scene_name)  


代码的复杂度可以自行扩展
我家全屋智能的HA设置 https://github.com/relliky/Tais_Home_Assistant_Config
回复

使用道具 举报

0

主题

52

回帖

173

积分

注册会员

积分
173
金钱
121
HASS币
0
发表于 2023-4-17 13:32:16 | 显示全部楼层
在下对你的景仰犹如滔滔长江之水,连绵不绝.
回复

使用道具 举报

3

主题

104

回帖

756

积分

高级会员

积分
756
金钱
649
HASS币
0
发表于 2023-4-18 09:32:54 | 显示全部楼层
厉害了。
回复

使用道具 举报

33

主题

1115

回帖

5488

积分

论坛元老

积分
5488
金钱
4325
HASS币
90
 楼主| 发表于 2023-4-22 21:34:59 | 显示全部楼层
hackyjso 发表于 2023-4-4 10:37
看不懂但是感觉很牛的样子,

刚刚终于把基本原理部分更新完啦,如果哪还有看不懂我再改进一下
我家全屋智能的HA设置 https://github.com/relliky/Tais_Home_Assistant_Config
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-8-18 02:52 , Processed in 0.700352 second(s), 12 queries , MemCached On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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