Skip to content
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

New 'Duty Time' sensor component #5069

Merged
merged 8 commits into from Jul 12, 2023
Merged

Conversation

dudanov
Copy link
Contributor

@dudanov dudanov commented Jul 7, 2023

What does this implement/fix?

The component Duty Time is used to calculate the operating time of something, for example, a light bulb in seconds.

It is configured by one of the logical sources: a binary_sensor or a lambda function.

The main loop checks the source for a change in the input signal. The auxiliary interval loop update() of the PollingComponent class periodically updates the sensor.

If necessary, it is possible to add an auxiliary sensor to record the time of the last switch-on.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • 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#3049

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040

Example entry for config.yaml:

# Example
# Test "object"
switch:
  - platform: template
    name: Test Object
    id: my_switch
    optimistic: on

# binary_sensor
binary_sensor:
  - platform: template
    id: my_binary_sensor
    name: Object State
    lambda: "return id(my_switch).state;"

# Reset Button
button:
  - platform: template
    name: Reset Duty Time
    on_press:
      sensor.duty_time.reset: id_duty

# duty_time component
sensor:
  - platform: duty_time
    id: id_duty
    name: Duty Time
    restore: on
    last_time:
      name: Last Duty Time
    # binary_sensor as logical source
    sensor: my_binary_sensor
    # .. EOR lambda
    #lambda: "return id(my_switch).state;"

Checklist:

  • 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:

@probot-esphome
Copy link

probot-esphome bot commented Jul 7, 2023

Hey there @dudanov,
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 = ["@dudanov"]

And run script/build_codeowners.py

(message by NeedsCodeownersLabel)

@dudanov dudanov force-pushed the duty_time-component branch 4 times, most recently from cd13cfa to 2dad680 Compare July 8, 2023 05:57
@SeByDocKy
Copy link
Contributor

Sound an interesting addition. Can be useful for example to build a kind of "historical stats" if you can add a "period" field to compute the ratio. More adding an action to "reset" the sensor would be great too

@dudanov dudanov marked this pull request as ready for review July 8, 2023 13:55
@dudanov dudanov requested a review from jesserockz July 11, 2023 06:19
@dudanov dudanov marked this pull request as draft July 11, 2023 13:54
@dudanov dudanov marked this pull request as ready for review July 11, 2023 14:10
@jesserockz jesserockz merged commit a539197 into esphome:dev Jul 12, 2023
25 checks passed
@jesserockz jesserockz mentioned this pull request Jul 12, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jul 14, 2023
@dudanov dudanov deleted the duty_time-component branch July 27, 2023 06:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants