-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scheduler component #11
Conversation
Can read schedule json config file Can load custom rule_types
The schedule can read a schedule.json file and create time events
…scheduler # By Paulus Schoutsen # Via Paulus Schoutsen * 'dev' of https://github.com/balloob/home-assistant: (51 commits) Light test tests light profile loading Loader test tests now custom component loading Default config dir is now working_dir/config Add sun component test for state change Tweak light test to create correct exception Better light.xy_color parsing Added light component test coverage Renamed mock_switch_platform to mock_toggledevice_platform Expanded switch test to push it to 100% coverage Fix to make tests work on Travis CI Added tests for switch component Clean up code sun component tests Added test coverage for sun component Minor fix for Chromecast component Cleaned up tests a bit Added initial Chromecast test coverage Final test added to get to 100% coverage for groups Extended group tests Added group component tests Reorganized testing ...
I am not a big fan of the name scheduler as it implies time-related functionality. If we add support for state changes this will not hold. If I look at other systems they use the word 'rules', which I like. What do you think of naming it 'rules'? Rules (scheduler) |
Let's make sure we create an example |
""" Schedule the event """ | ||
pass | ||
|
||
def execute(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make sure the execute part is reused by all the different types (time, sun). Each type should then only have to implement the schedule method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had one thought that all events (or maybe rules) has to have a service that will be called when executed is called. But I don't want to limit a event to so that it has to have an service. It might want to do something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be great that if you add support for an extra action, that all other events get that functionality too? I don't see us getting into a situation where we want to allow a certain action to be done after a certain event takes place, but not another event.
I really like the structure you have decided for the components and I can see this being a great addition to Home Assistant. Just seeing this code gives me great ideas for the future:
|
entity_ids=description['entity_ids'], | ||
days=description['days']) | ||
|
||
for event_description in description['events']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
event_description
is a confusing name as we have a variable name called description
a few lines above it. Next to that event
is already used within Home Assistant. Calling it rule_data
would be less confusing
Knowing this is still very much a work in progress I tried to not be too picky with my comments. Hope you don't hate me 🐬 . |
The reason I like scheduler more than rules is that I want something to happen for each event. I would think that a rule group will do something if all the rules are satisfied and something else if not. Now we want something to happen based on some event:
If it were rules it could be
The rules could be checked in an interval and respond on the current state of hass but with a schedule we can schedule something to happen when that event occur. I agree that both components are similar but the rules component is more powerful. But we also might implement the rules component so that it works as the scheduler component? |
You are right that rules imply it is either on or off. And that's a valid point. I do see the component evolving that at a certain point it will add support for rules and would like the component name to still hold true. Maybe a name like Automation? But then I guess scheduler would still work too. We cannot use the class name Event inside the scheduler but should use something that better represents what the class does, ie EventListener. So we get TimeEventListener, SunEventListener, StateEventListener etc. I also agree with you on the RuleSet being a flawed name. I gave it some more thought and maybe we should use the word Group? That way we can have the schedule component also take over the task of defining groups, since, you know, it actually allows us to define groups. That way the information that is present in the JSON file for each group can be split up into:
|
Another idea I just had is to have the scheduler component only support the events from Home Assistant core out of the box: TimeChanged, StateChanged. A SunChanged listener would be defined in the sun component. Each component that supports this would have a method called setup_listener(config). You can then do something like this: def setup(hass, config):
for listener_config in listeners:
if event['type'] in ('time', 'state'):
# handle locally
else:
listener = get_component(event['type']).setup_listener(listener_config) |
3089a15
to
c08676a
Compare
* upstream/master: (60 commits) StateMachine is now case insensitive for entity ids Added an example component that does the bare minimum State card rendering now way more flexible Update README.md Update documentation for example component Add link to demo in README Add code to mock API for demo on home-assistant.io Moved documentation from GitHub source to home-assistant.io Make nmap mac regex more flexible to play nice with OS X Frontend: color switch icons yellow if on New strategy for defining number of used threads WeMo component exposes Insight info if available Only turn off the specified lights Fix default light and device group IDs Add nmap_tracker documentation Fix typo and default groups Specify devices for trigger nmap-based device tracking plugin Make block_till_stopped test more flexible Fix PyLint ...
* upstream/master: (104 commits) Fire a time_changed event every second Update example config with correct wink config Wink API is weird. If you delete a device from their API, they dont delete it. They just "hide" it Update the frontend with the new icon for sensor Minor refactor of build_frontend script to support linux, and not just mac Update script installs latest dependencies Fix flaky device scanner test Increased environment validation upon start Fix group names for switch, light and devices Disable pylint unused-argument check Fix device scanner test Better update schedules for cast and devicetracker Tweaks to the configurator UI Add tests, fix styling Add initial version of configurator component Fix tabs being selectable by clicking on header Data binding fix: Update instead of replace states New: State.last_updated represents creation date Update sensor icon for now Updates to resolve flake8 errors ...
Sorry for not doing something with this for a long time. I have been using this component for a couple of weeks now with a config that turns on my lights 45 minutes before the sun sets and turns them off at 22:30 and it works great. The config I'm using:
|
Hi! I did make an alternative but that should be considered a lite version, I feel that this approach is the future. I'll merge it in and we'll see how things evolve over time :-) |
Added you as a collaborator on the project. Trying out something I read. |
What do you think of this idea? |
Thanks for the collaborator permissions! I'll try to be helpful The idea is nice, but I see both advantages and disadvantages. I like that the scheduler component is separated from the other components so that it's not necessary to modify others components to add a new listener. But then again, if the listener is a part of the component, it's more likely that the listener will be updated if the component is updated. |
The advantages would be:
Time and state would still be things that should be supported out of the box by the scheduler component. |
Refactored a bit in 6f3ef12. What do you think about that? |
That's awesome! Might want to add a check if the component exists / is loaded by calling if domain in hass.components: On Wed, Jan 28, 2015 at 11:02 AM, Gustav Ahlberg [email protected]
+1 858 380 9709 ⋅ PaulusSchoutsen.nl |
* Avoid None comparison for zwave cover. * Just rely on unit from config for unit_of_measurement * Explicit return None * Mqtt (#11) * Explicit return None * Missing service and wrong service name defined * Mqtt state was inverted, and never triggering
* Avoid None comparison for zwave cover. * Just rely on unit from config for unit_of_measurement * Explicit return None * Mqtt (#11) * Explicit return None * Missing service and wrong service name defined * Mqtt state was inverted, and never triggering
* Host should be optional for apcupsd component (#3072) * Zwave climate Bugfix: if some setpoints have different units, we should fetch the o… (#3078) * Bugfix: if some setpoints have different units, we should fetch the one that are active. * Move order of population for first time detection * Default to config if None unit_of_measurement * unit fix (#3083) * humidity slider (#3088) * If device was off target temp was null. Default to Heating setpoint (#3091) * Fix for BLE device tracker (#3019) * Bug fix tracked devices * Added scan_duration configuration parameter * fix homematic climate implementation (#3114) * Allow 'None' MAC to be loaded from known_devices (#3102) * Climate and cover bugfix (#3097) * Avoid None comparison for zwave cover. * Just rely on unit from config for unit_of_measurement * Explicit return None * Mqtt (#11) * Explicit return None * Missing service and wrong service name defined * Mqtt state was inverted, and never triggering * Fixed Homematic cover (#3116) * Add missing docstrings (fix PEP257 issues) (#3098) * Add missing docstrings (fix PEP257 issues) * Finish sentence * Merge pull request #3130 from turbokongen/zwave_fixes Bugfix. climate and covermqt * Back out insteon hub and fan changes (#3062) * Bump version * Special frontend build for 0.27.2
* Backend support for importing waypoints from owntracks as HA zones * Added test for Owntracks waypoints import * Backend support for importing waypoints from owntracks as HA zones * Added test for Owntracks waypoints import * Removed redundant assignment to CONF_WAYPOINT_IMPORT_USER * Fixed zone test break and code style issues * Fixed style issues * Fixed variable scope issues for entities * Fixed E302 * Do not install pip packages in tests * EventBus: return function to unlisten * Convert automation to entities with services * Refactored zone creation based on code review feedback, enhanced configuration * Added unit test to enhance waypoint_whitelist coverage * Fix JSON encoder issue in recorder * Fix tests docstring * * Improved zone naming in waypoint import * Added more test coverage for owntracks and zone * Back to 0.28.0.dev0 * Code review feedback from @pavoni * Added bitfield of features for flux_led since we are supporting effects * Host should be optional for apcupsd component (#3072) * Use voluptuous for file (#3049) * Zwave climate Bugfix: if some setpoints have different units, we should fetch the o… (#3078) * Bugfix: if some setpoints have different units, we should fetch the one that are active. * Move order of population for first time detection * Default to config if None unit_of_measurement * unit fix (#3083) * humidity slider (#3088) * If device was off target temp was null. Default to Heating setpoint (#3091) * Fix linting * Upgrade pyuserinput to 0.1.11 (#3068) * Upgrade pyowm to 2.4.0 (#3067) * improve isfile validation check (#3101) * Refactor notification titles to allow for them to be None, this also includes a change in Telegram to only include the title if it's present, and to use a Markdown parse mode for messages (#3100) * Fix broken test * rfxtrx sensor clean up * Bitcoin sensor use warning instead of error (#3103) * Use voluptuous for HDMI CEC & CONF_DEVICES constants (#3107) * Update voluptuous for nest (#3109) * Update configuration check * Extend platform * Fix for BLE device tracker (#3019) * Bug fix tracked devices * Added scan_duration configuration parameter * fix homematic climate implementation (#3114) * Allow 'None' MAC to be loaded from known_devices (#3102) * Use voluptuous for xmpp (#3127) * Use voluptuous for twitter (#3126) * Use voluptuous for Fritzbox and DDWRT (#3122) * Use Voluptuous for BT Home Hub (#3121) * Use voluptuous for syslog (#3120) * Use voluptuous for Aruba (#3119) * Use constants, update configuration check, and ordering (Pilight) (#3118) * Use contants, update configuration check, and ordering * Fix pylint issue * Migrate to voluptuous (#3113) * Fix typo (#3108) * Migrate to voluptuous (#3106) * Update voluptuous (#3104) * Climate and cover bugfix (#3097) * Avoid None comparison for zwave cover. * Just rely on unit from config for unit_of_measurement * Explicit return None * Mqtt (#11) * Explicit return None * Missing service and wrong service name defined * Mqtt state was inverted, and never triggering * Migrate to voluptuous (#3096) * Migrate to voluptuous (#3084) * Fixed Homematic cover (#3116) * Migrate to voluptuous (#3069) 🐬 * Migrate to voluptuous (#3066) 🐬 * snapcast update (#3012) * snapcast update * snapcast update * validate config * use conf constants * orvibo updates (#3006) 🐬 * Update frontend * move units to temperature for climate zwave. wrong state was sent to mqtt cove * Use voluptuous for instapush (#3132) * Use voluptuous for Octoprint (#3111) * Migrate to voluptuous * Fix pylint issues * Add missing docstrings (fix PEP257 issues) (#3098) * Add missing docstrings (fix PEP257 issues) * Finish sentence * Updated braviatv's braviarc version to 0.3.4 (#2997) * Updated braviarc version to 0.3.4 * Updated braviarc version to requirements_all.txt * Use voluptuous for Acer projector switch (#3077) 🐬 * Use voluptuous for twilio (#3134) * Use voluptuous for webostv (#3135) * Use voluptuous for Command line platforms (#2968) * Migrate to voluptuous * Fix pylint issues * Remove FIXME * Split setup test * Test with bootstrap * Remove lon and lat * Fix pylint issues * Add coinmarketcap sensor (#3064) * Migrate to voluptuous (#3142) 🐬 * Back out insteon hub and fan changes (#3062) * Move details to docs (#3146) * Update frontend * Use constants (#3148) * Update ordering (#3149) * Migrate to voluptuous (#3092) * Display the error instead of the traceback (notify.slack) (#3079) * Display the error instead of the traceback * Remove name for check * Automatic ODB device tracker & device tracker attributes (#3035) * Migrate to voluptuous (#3173) * Add voluptuous for tomato and SNMP (#3172) * Improve voluptuous and login errors for Asus device tracker (#3170) * Add exclude option to nmap device tracker (#2983) * Add exclude option to nmap device tracker Adds an optional exclude paramater to nmap device tracker. Devices specified in the exclude list will never be scanned by nmap. This can help to reduce log spam. ex: ``` device_tracker: - platform: nmap_tracker hosts: 10.0.0.1/24 home_interval: 1 interval_seconds: 12 consider_home: 120 track_new_devices: yes exclude: - 10.0.0.2 - 10.0.0.1 ``` * Handle optional exclude * Style fixed * Added Xbox Live component (#3013) * Added Xbox Live component * Added Xbox Live sensor to coveralls * Added init success checks * Added entity id * Adding link_names to post.message call (#3167) If you do not turn link_names on, Slack will not highlight @channel and @username messages. * Allow https (fixes #3150) (#3155) * Use constants (#3156) * Bugfix: ctach Runtime errors (#3153) "RuntimeError: Disable scan failed" has been seen in a live installation * Migrate to voluptuous (#3166) 🐬 * Migrate to voluptuous (#3164) 🐬 * Migrate to voluptuous (#3163) 🐬 * Migrate to voluptuous (#3162) 🐬 and 🍪 for fixing quotes! * Exclude www_static from pydocstyle linting (#3175) 🐬 * Migrate to voluptuous (#3174) * Migrate to voluptuous (#3171) * Use voluptuous for mFi switch (#3168) * Migrate to voluptuous * Take change configuration into account * Migrate to voluptuous (#3144) 🐬 * Add the occupancy sensor_class (#3176) Such a complicated PR * Update frontend * Use voluptuous for Unifi, Ubus (#3125) * Using alert with Hue maintains prior state (#3147) * When using flash with hue, dont change the on/off state of the light so that it will naturally return to its previous state once flash is complete * ATTR_FLASH not ATTR_EFFECT * MQTT fan platform (#3095) * Add fan.mqtt, allow brightness to be passed and mapped to a fan speed for compatibility with emulated_hue * Pylint/Flake8 fixes * Remove brightness * Add more features, like custom oscillation/speed payloads and setting the speed list * Flake8 fixes * flake8/pylint fixes * Use constants * block fan.mqtt from coverage * Fix oscillating comment * Add Sphinx API doc generation (#3029) * add's sphinx project to docs/ dir * include core/helpers autodocs for API reference * Allow reloading automation without restarting HA (#3002) * Migrate to voluptuous (#3182) 🐬 * Migrate to voluptuous (#3179) 🐬 * Added scale and offset to the Temper component (#2853) 🐬 * Use voluptuous for BT and Owntracks device trackers (#3187) 🐬 * Correct binary_sensor.ecobee docs URL * Use voluptuous for Hikvisioncam switch (#3184) * Migrate to voluptuous * Use vol.Optional * Use voluptuous for Edimax (#3178) 🐬 * Use voluptuous for Bravia TV (#3165) 🐬 * Added support to 'effect: random' to Osram Lightify lights (#3192) * Added support to 'effect: random' to Osram Lightify lights * removed extra line not required * Use voluptuous for message_bird, sendgrid (#3136) * Try out the RTD theme * Doc updates * Update voluptuous for existing notify platforms (#3133) * Update voluptuous for exists notify platforms * fix constants * Simple trend sensor. (#3073) * First cut of trend sensor. * Tidy. * Migrate to voluptuous (#3193) * Migrate to voluptuous (#3194) 🐬 * Migrate to voluptuous (#3197) * Migrate to voluptuous (#3198) 🐬 * Use extend of PLATFORM_SCHEMA (#3199) * Migrate to voluptuous (#3202) 🐬 * Updated to use the occupancy sensor_class (#3204) 🐬 * Migrate to voluptuous (#3206) * Migrate to voluptuous (#3207) * Migrate to voluptuous (#3208) 🐬 * Migrate to voluptuous (#3209) 🐬 * Migrate to voluptuous (#3214) * Use voluptuous for SqueezeBox (#3212) * Migrate to voluptuous * Remove name * Migrate to voluptuous and upgrade uber_rides to 0.2.5 (#3181) * Migrate to voluptuous (#3200) 🐬 * Use Voluptuous for Luci and Netgear device trackers (#3123) * Use Voluptuous for Luci and NEtgear device trackers * str_schema shortcut * Undo str_schema * change update handling with variable for breack CCU2 (#3215) * Update ordering (#3216) * Docs update * Flake8/pylint * Add new docs requirements * Update email validation (#3228) 🐬 * Fix email validation (fixes #3138) (#3227) * Upgrade slacker to 0.9.25 (#3224) * Upgrade psutil to 4.3.1 (#3223) * Upgrade gps3 to 0.33.3 (#3222) * Upgrade Werkzeug to 0.11.11 (#3220) * Upgrade sendgrid to 3.4.0 (#3226) * Bluetooth: keep looking for new devices (#3201) * keep looking for new devices * Update bluetooth_tracker.py * change default value for tracking new devices * remove commented code * dlink switch added device state attributes and support for legacy firmware (#3211) * Use voluptuous for free mobile (#3236) * Use voluptuous for nma (#3241) * Improve 1-Wire device family detection and error checking. Use volupt… (#3233) * Improve 1-Wire device family detection and error checking. Use voluptuous * Fix detection of gpio connected devices * Replace rollershutter and garage door with cover, add fan (#3242) * Use voluptuous for Alarm.com (#3229) * Use voluptuous for gntp (#3237) * Use voluptuous for pushbullet, pushetta and pushover (#3240) * Migrate to voluptuous (#3230) 🐬 * Fix mFi sensors in uninitialized state (#3246) If mFi sensors are identified but not fully assigned they can have no tag value, and mficlient throws a ValueError to signal this. This patch handles that case by considering such devices to always be STATE_OFF. * Use voluptuous for PulseAudio Loopback (#3160) * Migrate to voluptuous * Fix conf var * Use voluptuous for Verisure (#3169) * Migrate to voluptuous * Update type and add missing config variable * thread safe modbus (#3188) * Upgraded fitbit to version 0.2.3 which fixed oauthlib.oauth2.rfc6749.errors.TokenExpiredError: (token_expired) (#3244) * update ffmpeg version to 0.10 add get image to camera (#3235) * Migrate to voluptuous (#3234) * fix bugfix with unique_id (#3217) * Zwave climate fix and wink cover. (#3205) * Fixes setpoint get was done outside loop * zxt_120 * Wink not migrated to cover * Clarifying debug * too long line * Only add 1 device entity * Owntracks voluptuous fix (#3191) * Zwave set temperature fix (#3221) * If device was off set target temp would not work. * Changed to use a workaround just for Horstmann HRT4-ZW Zwave Thermostat * Wrong Horseman id * style changes * Change PR to suggestion on gitter (#3243) * Reload groups (#3203) * Allow reloading groups without restart * Test to make sure automation listeners are removed. * Remove unused imports for group tests * Simplify group config validation * Add prepare_reload function to entity component * Migrate group to use entity_component.prepare_reload * Migrate automation to use entity_component.prepare_reload * Clean up group.get_entity_ids * Use cv.boolean for group config validation * fix remove listener (#3196) * Add linux battery sensor (#3238) * protect service data for changes in calls (#3249) * protect service data for changes in calls * change handling * move MappingProxyType to service call * Fix issue #3250 (#3253) * Minor Ecobee changes (#3131) * Update configuration check, ordering, and constants * Make API key optional * issue #3250 * Add voluptuous to ecobee (#3257) * Use constants and update ordering (#3261) * Add support for complex template structures to data_template (#3255) * Improve yaml fault tolerance and handle check_config border cases (#3159) * Use voluptuous for nx584 alarm (#3231) * Migrate to voluptuous * Fix pylint issue * fastdotcom from pypi (#3269) * Use constants and update ordering (#3268) 🐬 * Use constants and update ordering (#3267) 🐬 * Add additional template for custom date formats (#3262) I can live with a few visual line breaks 🐬 * Use constants and update ordering (#3266) * Updated braviatv's braviarc version to 0.3.5 (#3271) * Use voluptuous for Device Sun Light Trigger (#3105) * Migrate to voluptuous * Use default * Point to master till archive is back (#3285) * Pi-Hole statistics sensor (#3158) * Add Pi-Hole sensor * Update docstrings and remove print() * Use None for payload * Added stuff for support range setting (#3189) * cleanup Homematic code (#3291) * cleanup old code * cleanup round 2 * remove unwanted platforms * Update frontend * Hotfix for #3100 (#3302) * Fix TP-Link Archer C7 long passwords (#3225) * Fix tplink C7 long passwords Fixes an issue where passwords longer than 15 chars could not log in to Archer C7 routers. * Truncate in correct place * Add comment about TP-Link C7 pass truncation * Fix lint error * Truncate comment at 79 chars not 80 * modbus write registers service (#3252) * Fix bloomsky platform discovery (#3303) * Remove dev tag
A scheduler component