From c6b74de13c0117de9e2fb6a9e787580234243866 Mon Sep 17 00:00:00 2001 From: Richard Arends Date: Sun, 12 Jan 2025 15:33:14 +0100 Subject: [PATCH] Add Active state map (#74) * Add Active State Map --- CHANGELOG.md | 7 +++++++ heatpump.yaml | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd4da03..474f11a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/heatpump.yaml b/heatpump.yaml index 45e335d..50fabce 100644 --- a/heatpump.yaml +++ b/heatpump.yaml @@ -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 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'