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

Add Active state map #74

Merged
merged 3 commits into from
Jan 12, 2025
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.1.0] - 2025-01-12

### Added

- Active State Map: A sensor that represents the state as a number. This can be used for example in Grafana to plot a state time timeline
- 0: Inactive, 1: Heating, 2: Cooling, 3: DHW, 4: Defrosting, 99: Unknown (no mapping found)

## [5.0.0] - 2024-11-24

### Changed
Expand Down
23 changes: 22 additions & 1 deletion heatpump.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ esphome:
friendly_name: "${description}"
project:
name: "${devicename}.${description}"
version: 4.1.2
version: 5.0.0

esp32:
board: esp32dev
Expand Down Expand Up @@ -1104,6 +1104,27 @@ sensor:
int t1s_dhw = t5 + dt1s5;
return t1s_dhw;

- platform: template
name: "Active State Map"
id: "${devicename}_active_state_map"
unit_of_measurement: ""
accuracy_decimals: 0 # No decimals, value will show as integer
lambda: |-
static const std::map<std::string, int> status_map = {
{"Inactive", 0},
{"Heating", 1},
{"Cooling", 2},
{"DHW", 3},
{"Defrosting", 4}
};

auto state_item = status_map.find(id(${devicename}_active_state).state);
if (state_item != status_map.end()) {
return state_item->second; // Return integer value that matches the string value (Heating, Cooling, etc..)
} else {
return 99; // No mapping found
}

binary_sensor:
# Register: 0 -> Is also read as 'sensor' to read the complete value, used for the templated 'switch'(es)
# Bit: 0 -> Is present in this config as a 'switch'
Expand Down
Loading