esphome / esphome/feature-requests

Add helper function for int/float/double sensor values the need to be used via char array

Open
#1,722 0 comments 0 reactions 0 assignees View on GitHub
enhancement
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**
I do need to send sensor value to mqtt. The sensor data is double. The mqtt publish excepts a char array.

**Please describe your use case for this integration and alternatives you've tried:**
It would be nice to have some helper functions to convert the double / float / int to a char array and select the number of decimals you want to have.

**Additional context**
I know now by the help of @jesserockz that I can use `to_string((uint8_t)x)` in my lambda, but for less skilled programmers (as I am, too) it would be nice to have a helper function that you can use without deeper knowledge...

right now there is the other way around:
https://esphome.io/api/helpers_8h.html
[esphome::parse_number](https://esphome.io/api/namespaceesphome.html#a7b2cdc773a280b213f389c371899ee5c) (const char *str)

It would be nice to have
(don't go after me, I am not a real developer)
```
esphome::parse_number (const int *i)
esphome::parse_number (const double *d, precision)
esphome::parse_number (const float *f, sonst precision)
```

... rand these functions are eturning a char_array that can be used for other esphome functions.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the documented esphome::parse_number API in helpers_8h.html and review how its existing string-to-number helper is exposed. Define the requested numeric-to-char-array behavior for int, float, and double values, including precision, then verify that the result can be passed to MQTT publishing functions.

Written by the indexing model from the issue text.

Assessment

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.