本帖最后由 叫我刘哥就好了 于 2023-9-21 23:06 编辑
大佬说的很对,确实自动化就是应该用来简便操作的。所有自动化都走pyscript的话确实有些南辕北辙了。这是写在哪些个配置文件里的,看格式应该是yaml。
我是这样使用的
@time_trigger("period(0:00, 5 sec)")
@state_active("pyscript.ok1 == '1'")
def every_5_seconds():
pyscript.room_occupancy_state_machine(occupancy_entity_str = "input_select.occupy",
motion_str = "binary_sensor.f4b3b19d3b8f_motion",
motion_on_ratio_for_x_min_str = "input_number.number1",
motion_on_ratio_for_2x_min_str = "input_number.number2",
room_type = "study room")
这是我在jupyter里面的代码,然后再监听这个变量的变化
from homeassistant.const import EVENT_STATE_CHANGED
@event_trigger(EVENT_STATE_CHANGED, "entity_id == 'input_select.occupy'")
def monitor_state_change(entity_id=None, new_state=None, old_state=None):
old_value = old_state.state if old_state else None
log.info(f"entity {entity_id} changed from {old_value} to {new_state.state} and attributes are now {new_state.attributes}")
if old_state.state == "Outside" and new_state.state == "Just Entered":
switch.studyroom_switch_2.turn_on()
elif old_state.state == "Just Entered" and new_state.state == "Outside":
switch.studyroom_switch_2.turn_off()
另外请问那两个数字参数代表着什么?
此外我对大佬的 无线开关递归控制灯的代码很有兴趣,请问哪里可以看的到呢? |