esphome / esphome/feature-requests

Ability to Set Duty Time Sensor

Open
#3,075 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
450
Forks
29
PR merge metrics
No merged PRs in 30d

Description

**Describe the problem you have/What new integration you would like**

Add the ability to set the time for duty time. This would allow you to store the value in a global variable on an interval. The value could then be restored to the sensor value on startup. Currently, without being able to set the duty_time, the only way to restore the value is using `restore`. This method gives the warning that it could wear out the flash.

**Please describe your use case for this integration and alternatives you've tried:**

The use case it to try and preserve the flash.

**Additional context**

Example
```yaml
sensor:
- platform: duty_time
id: duty_time_daily
name: Daily Runtime
lambda: |-
return id(valve).state;
restore: False
update_interval: 60s

# Global variables store the duty times
# This is to preserve flash and not write every few seconds.
globals:
- id: global_duty_time_daily
type: int
restore_value: True

interval:
# Save to global
- interval: 5min # whatever interval
then:
- lambda: |-
id(global_duty_time_daily) = id(duty_time_daily).state;

esphome:
on_boot:
then:
- duty_time.set: # <- this would now be possible
id: duty_time_daily
value: !lambda 'return id(global_duty_time_daily);'
```

Contributor guide

No contributing guide indexed for this repository

Research direction

No files or tests are named. Start by locating the duty_time sensor implementation and its existing restore handling, then trace how sensor actions are declared and initialized at on_boot. Done means the YAML example can set the stored duty time without relying on frequent flash writes.

Written by the indexing model from the issue text.

Assessment

Tech stack
yaml
Domain
embedded-iot
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.