j0ta29 / esphome

ESPHome is a system to control your ESP8266/ESP32 by simple yet powerful configuration files and control them remotely through Home Automation systems.
https://esphome.io/
Other
6 stars 2 forks source link

Allow negative Number values #3

Closed abuisine closed 4 months ago

abuisine commented 7 months ago

Context: Some addresses, while being considered as a number, can receive negative values. Example : The heating curve shift parameter should be settable from -14°C to +40°C.

Problem: The current implementation does not allow negative values. Example : The heating curve shift parameter is actually limited to the 0°C/+40°C range.

j0ta29 commented 7 months ago

Will come!

abuisine commented 6 months ago

Do you plan to correct this on the actual implementation, or are you waiting for the rewrite ?

I am asking because I plan to modulate the boiler from opentherm through the curve offset and would need to go in the negative values.

j0ta29 commented 6 months ago

@abuisine , sorry for the late response. I am currently abroad, leisure time is limited. I reworked the current development branch with improvements concerning https://github.com/j0ta29/esphome/issues/2 (not finally finished) and this issue (ready to test). See the example below how to use this branch. As I currently have limited testing possibility (only VPN, but 1500km between me and my boiler) I'm not able to verify that negative values are correctly written to the Viessmann unit. At least reading the values with a sensor says that it should be okay. If you are willing to perform a test and give me feedback there are a few points to consider:

text_sensors now require a mode configuration value (one of MAP, RAW, DEVICE_INFO, STATE_INFO, ...), the configuration value raw is discontinued.

optolink's configuration values device_info and state are discontinued. Use a text_sensor with fitting mode instead (see above).

Example:

external_components:
  - source:
      type: git
      url: https://github.com/j0ta29/esphome
      ref: weekly_schedules
    components: [ optolink ]

optolink:
  protocol: P300

text_sensor:
  - platform: optolink
    mode: DEVICE_INFO
    name: Device info
    update_interval: 600s
abuisine commented 6 months ago

I will give it a try this WE

abuisine commented 6 months ago

Unfortunately I was not able to compile :

src/esphome/components/optolink/number/optolink_number.cpp: In member function 'virtual void esphome::optolink::OptolinkNumber::datapoint_value_changed(uint8_t)':
src/esphome/components/optolink/number/optolink_number.cpp:26:20: error: 'sint8_t' was not declared in this scope
     publish_state((sint8_t) state);
                    ^~~~~~~
src/esphome/components/optolink/number/optolink_number.cpp:26:20: note: suggested alternative: 'uint8_t'
     publish_state((sint8_t) state);
                    ^~~~~~~
                    uint8_t
src/esphome/components/optolink/number/optolink_number.cpp: In member function 'virtual void esphome::optolink::OptolinkNumber::datapoint_value_changed(uint16_t)':
src/esphome/components/optolink/number/optolink_number.cpp:34:20: error: 'sint16_t' was not declared in this scope
     publish_state((sint16_t) state);
                    ^~~~~~~~
src/esphome/components/optolink/number/optolink_number.cpp:34:20: note: suggested alternative: 'uint16_t'
     publish_state((sint16_t) state);
                    ^~~~~~~~
                    uint16_t
src/esphome/components/optolink/number/optolink_number.cpp: In member function 'virtual void esphome::optolink::OptolinkNumber::datapoint_value_changed(uint32_t)':
src/esphome/components/optolink/number/optolink_number.cpp:42:20: error: 'sint32_t' was not declared in this scope
     publish_state((sint32_t) state);
                    ^~~~~~~~
src/esphome/components/optolink/number/optolink_number.cpp:42:20: note: suggested alternative: 'uint32_t'
     publish_state((sint32_t) state);
                    ^~~~~~~~
                    uint32_t
*** [.pioenvs/optolink/src/esphome/components/optolink/number/optolink_number.cpp.o] Error 1
========================= [FAILED] Took 73.45 seconds =========================

For the record I use some numbers in my configuration (which works fine with the usual branch) :

number:
  - platform: optolink
    name: Reduced room temperature setpoint
    unit_of_measurement: °C
    address: 0x3307
    bytes: 1
    min_value: 3
    max_value: 37
    step: 1
    mode: box
    icon: "mdi:home-thermometer-outline"
    device_class: temperature
    update_interval: 120s
  - platform: optolink
    name: Heating curve level
    address: 0x3304
    bytes: 1
    # min_value: -13 not accepted
    min_value: 0
    max_value: 40
    step: 1
    mode: box
    icon: "mdi:chart-bell-curve-cumulative"
    disabled_by_default: true
    device_class: temperature
    update_interval: 120s
  - platform: optolink
    name: Heating curve slope
    address: 0x3305
    bytes: 1
    step: 0.1
    div_ratio: 10
    min_value: 0.2
    max_value: 3.5
    mode: box
    icon: "mdi:chart-bell-curve-cumulative"
    disabled_by_default: true
    update_interval: 120s
j0ta29 commented 6 months ago

Which version of ESPHome do you use?

abuisine commented 6 months ago

ESPHome 2023.12.5

j0ta29 commented 6 months ago

Okay, I forgot to test the ESP32 platform. Would you give it another try?

abuisine commented 6 months ago

Seems to be ok :

I do not have access right now to verify on the boiler itself, and temperatures are too high for the boiler to be heating.

Side notes :

In any case, thanks a lot ! I leave it running as is and will report any issue

j0ta29 commented 4 months ago

Fixed and tested in new release.