Commit Graph

6 Commits

Author SHA1 Message Date
remiolivier
da90344ffc fix: Unable to change the set point when Home Assistant is configured with Fahrenheit temperature unit (#73)
# Fix Temperature Handling in Fahrenheit Mode

## Problem

When operating in **Fahrenheit mode**, Mysa still expects temperature
values to be provided in **Celsius**.
However, Home Assistant sends integer Fahrenheit values (e.g.,
`72.02°F`), which convert to **non-aligned Celsius values** like
`22.22°C`.

Mysa’s API only accepts temperature values that are either **whole
numbers** or **increments of 0.5°C** (for example: `21.0`, `21.5`,
`22.0`).
As a result, values such as `22.22°C` or `21.72°C` are considered
invalid and are **rejected** by Mysa’s API.

---

## Root Cause

- The original code accepted **0.1°C precision** and **0.5°C step
size**.
- When Home Assistant runs in Fahrenheit, the conversion from °F to °C
produces fractional values that are not valid (e.g., 72°F → 22.22°C).
- Because Mysa enforces strict 0.5°C increments, these fractional
setpoints caused failed updates.

---

## Solution

This update ensures valid behavior when using Fahrenheit mode **while
keeping the current behavior for Celsius**:

- Adds a new environment variable:  
  **`M2M_TEMP_UNIT`** — accepts either:
  - `C` *(default)*
  - `F` *(for Fahrenheit operation)*
- When running in Fahrenheit mode (`M2M_TEMP_UNIT=F`):
  - Celsius values are **rounded and clamped to the nearest 0.5°C**.  
  - Temperature step size and precision are adjusted:
    - Precision → `1°F`
    - Step size → `1°F`
- When running in Celsius mode, existing logic remains unchanged (0.1
precision, 0.5 step).

---

## Technical Summary

| Mode | Env Variable | Precision | Step | Conversion Behavior |
|------|---------------|------------|------|----------------------|
| Celsius | `M2M_TEMP_UNIT=C` (default) | 0.1°C | 0.5°C | Direct
pass-through |
| Fahrenheit | `M2M_TEMP_UNIT=F` | 1°F | 1°F | Convert °F → °C, snap to
0.5°C |

The rounding logic ensures that when a Fahrenheit value (e.g., `72°F`)
is converted to Celsius (`21.72°C`), it is adjusted to the nearest valid
half-degree (`21.5°C` or `22.0°C`).

# Demo


https://github.com/user-attachments/assets/bbffe5fe-a3be-43cb-aed0-f63bdfacb1d4

---------

Co-authored-by: Pascal Bourque <pascal@cosmos.moi>
2025-11-02 10:00:14 -05:00
Pascal Bourque
a47cdbb45e fix: Don't crash on undefined values returned by the Mysa API (#81) 2025-11-01 10:49:27 -04:00
Pascal Bourque
374dae1885 feat: Expose device serial number and origin (#7) 2025-06-07 10:58:41 -04:00
Pascal Bourque
2e2e64d2d0 feat: Temperature and humidity sensors (#6) 2025-06-07 09:35:48 -04:00
Pascal Bourque
b7a80cb072 build: Build and publish a proper CLI tool with options, also packaged as a Docker image (#2)
* Renamed environment variables

* Moved MqttSettings to main.tsx

* Using Commander for CLI arguments

* PinoLogger

* Option for json log format

* Updated mysa-js-sdk to latest version

* Moved options to their own module

* Extracted session file management to the session module

* Added deviceId meta to thermostat instance logger

* Display version from package.json; added copyright

* Create README.md

* Build with tsup

* Update .gitignore

* Remove prepublishOnly npm script

* Distributed CLI executable is now working

* Update README.md

* Dockerfile

* Minify the build output

* Update README.md

* Create initial Github workflow

* Create release.config.mjs

* Read package version at run-time, not build-time

* Update README.md

* Create CONTRIBUTING.md

* WIP: docker CI job

* Trying multiple tags

* Enable docker build cache

* Testing the docker build cache

* Dockerfile: set npm version in final stage for better caching

* Testing docker build cache

* Moved VERSION arg to the final build stage

* Finalized the `docker` build job

* Added copyright header to all source files

* Specify radix when parsing integer options
2025-06-06 11:33:18 -04:00
Pascal Bourque
7a3f94c37e feat: Mysa baseboard thermostats (#1) 2025-06-02 13:59:43 -04:00