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

Apply filters before rounding values #64

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ to any number of different targets, such as databases or MQTT.
* [Installation and usage](#installation-and-usage)
+ [Running with Docker](#running-with-docker)
+ [Running as a systemd service](#running-as-a-systemd-service)
* [Caveats](#caveats)
* [Development](#development)
* [License](#license)

Expand Down Expand Up @@ -112,6 +113,10 @@ There is a skeleton systemd service available in [systemd/eachwatt.service](syst
project to `/opt/eachwatt`, copy the service file to `/etc/systemd/system/eachwatt.service`, modify it as necessary
and then start the service using `systemctl start eachwatt.service`.

## Caveats

* IotaWatt input sensors are always whole numbers, i.e. 2 watts. Output sensors don't have this limitation.

## Development

Install dependencies:
Expand Down
10 changes: 5 additions & 5 deletions src/eachwatt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ const mainPollerFunc = async (config: Config) => {

// Post-process power sensor data
powerSensorData = powerSensorData.map((data) => {
// Apply optional data filters
if (data.circuit.sensor.filters) {
data = applyFilters(data.circuit.sensor.filters, data)
}

if (data.power !== undefined) {
// Round all numbers to one decimal point
data.power = Number(data.power.toFixed(1))

// Apply optional data filters
if (data.circuit.sensor.filters) {
data = applyFilters(data.circuit.sensor.filters, data)
}
}

return data
Expand Down
Loading