Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Using map and list comprehension #467

Unanswered
jonathan-morton asked this question in Q&A
Discussion options

Hi, so I'm just getting started and it has been years since I've used Python so apologies if I am missing something obvious
It seems like when I use map or list comprehension in a time trigger the result is not being updated

I have the Jupyter notebook setup and the body of turn_off() works fine when run once when the lights are on

LIGHTS_BATHROOM = [
 light.bathroom_overhead_1,
 light.bathroom_overhead_2,
 light.bathroom_overhead_3
]
@time_trigger("period(0:00, 5 sec)")
def turn_off():
 light_is_on = [light == "on" for light in LIGHTS_BATHROOM]
 #light_is_on = list(map(lambda light: light == "on", LIGHTS_BATHROOM))
 if any(light_is_on):
 if binary_sensor.bathroom_motion_occupancy == "off":
 light.turn_off(
 entity_id=LIGHT_BATHROOM_IDS
 )
 else:
 log.debug(f"motion sensor status: {binary_sensor.bathroom_motion_occupancy}")
 log.debug(f"contact sensor status: {binary_sensor.bathroom_door_contact}")

But the console outputs the following continuously even when the lights have been turned on

file.bathroom.turn_off: calling any([False, False, False], {})

If I update the condition to

if light.bathroom_overhead_1 == "on" or light.bathroom_overhead_2 == "on" or light.bathroom_overhead_3 == "on":
 if binary_sensor.bathroom_motion_occupancy == "off":
 light.turn_off(
 entity_id=LIGHT_BATHROOM_IDS
 )

It works as expected

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /