esphome
esphome copied to clipboard
[time] Add template platform
What does this implement/fix?
Add a template platform. Allows the use of the time component on offline devices.
Also adds the possibily to change the system time by code
Types of changes
- [ ] Bugfix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Other
Related issue or feature (if applicable): fixes
Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#<esphome-docs PR number goes here>
Test Environment
- [x] ESP32
- [ ] ESP32 IDF
- [ ] ESP8266
- [ ] RP2040
- [ ] BK72xx
- [ ] RTL87xx
Example entry for config.yaml:
esphome:
name: time
esp32:
board: nodemcu-32s
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
web_server:
version: 3
logger:
level: debug
time:
- platform: template
id: template_time
timezone: Europe/Berlin
button:
- platform: template
name: hit me
on_press:
then:
- system_time.set:
id: template_time
datetime: "2034-10-05 10:10"
datetime:
- platform: template
name: Set System Time
optimistic: true
type: datetime
on_value:
then:
lambda: |-
id(template_time).set_time(x);
- platform: template
name: Set System Time UTC
optimistic: true
type: datetime
on_value:
then:
lambda: |-
id(template_time).set_time(x, true);
interval:
- interval: 1s
then:
- logger.log:
format: "seconds: %d"
args: [ 'id(template_time).timestamp_now()' ]
- logger.log:
format: "utc: %s"
args: [ 'id(template_time).utcnow().strftime("%Y-%m-%d %H:%M:%S").c_str()' ]
- logger.log:
format: "local: %s"
args: [ 'id(template_time).now().strftime("%Y-%m-%d %H:%M:%S").c_str()' ]
Checklist:
- [x] The code change is tested and works locally.
- [ ] Tests have been added to verify that the new code works (under
tests/folder).
If user exposed functionality or configuration variables are added/changed:
- [ ] Documentation added/updated in esphome-docs.
Hey there @ottowinter, mind taking a look at this pull request as it has been labeled with an integration (time) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)
Hey there @RFDarter,
Thanks for submitting this pull request! Can you add yourself as a codeowner for this integration? This way we can notify you if a bug report for this integration is reported.
In __init__.py of the integration, please add:
CODEOWNERS = ["@RFDarter"]
And run script/build_codeowners.py
(message by NeedsCodeownersLabel)
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 55.10%. Comparing base (
4d8b5ed) to head (e04ead4). Report is 2148 commits behind head on dev.
Additional details and impacted files
@@ Coverage Diff @@
## dev #7621 +/- ##
==========================================
+ Coverage 53.70% 55.10% +1.39%
==========================================
Files 50 50
Lines 9408 9905 +497
Branches 1654 1354 -300
==========================================
+ Hits 5053 5458 +405
- Misses 4056 4097 +41
- Partials 299 350 +51
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
🚀 New features to boost your workflow:
- ❄ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
What actually is still blocking this component? Is it just the docs?
Yep, docs are needed before it gets in the list of jessy to review it. My devcontainer is making me trouble at the moment and i haven't had time time to fix it.
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes. Thank you for your contribution!