tomvoo
(Tom)
May 2, 2024, 6:15pm
1
Hi there,
I’m trying to control my water heat-pump and the temperature values require some conversion to become celcius. Like so:
Celcius = (value - 30) / 2
It looks like it’s Fahrenheit but it’s actually not so I cannot use the built-in C → F / F → C conversion.
For reading the registers i’ve already made a template function like so:\
- sensor:
- name: water_heatpump_current_temperature_celcius
state: "{{ (((states('sensor.water_heatpump_current_temperature') | int)-30) / 2)|round(0) }}"
unit_of_measurement: "°C"
device_class: temperature
state_class: measurement
- name: water_heatpump_target_temperature_celcius
state: "{{ (((states('sensor.water_heatpump_target_temperature') | int)-30) / 2)|round(0) }}"
unit_of_measurement: "°C"
device_class: temperature
state_class: measurement
I prefer to use a climates sensor to achieve this because of the UI but if that doesn’t work i’d like to know how to just go about writing converted values.
Thanks
tom_l
May 3, 2024, 12:43am
2
You did not need to do that. The modbus sensor supports options you can use in the sensor definition to do the conversion.
So in your case just add this to your modbus sensor:
offset: -15
scale: 0.5
For writing, say you want to send the value 30
action:
- service: modbus.write_register
data_template:
address: # supply this
unit: # supply this
hub: # supply this
value: >
{% set value = 30 %}
{{ (2 * value + 30)|round(0)|int(0) }}
If you wanted to send the value of an input number or sensor:
value: >
{% set value = states('input_number.foobar')|float(0) %}
{{ (2 * value + 30)|round(0)|int(0) }}
value: >
{% set value = states('sensor.foobar')|float(0) %}
{{ (2 * value + 30)|round(0)|int(0) }}
tomvoo
(Tom)
May 3, 2024, 6:04am
3
@tom_l Thanks Tom! I missed those inline conversions! Would this also work for the climates
component?
tom_l
May 3, 2024, 7:38am
4
It has the same options: Modbus - Home Assistant It appears to be a global setting for the climate entity though.
tomvoo
(Tom)
May 3, 2024, 12:12pm
5
@tom_l Thanks again, i got it working!
tomvoo
(Tom)
May 3, 2024, 1:08pm
6
hey @tom_l sorry to hijack this again, but you might have an idea on this. After I added the climate component which reads the current temperature from address 113 it seems the original sensor current_temperature
is showing as Unavailable.
sensors:
- name: water_heatpump_current_temperature
unique_id: f8c8a1a9-ef93-4764-a744-2aeeaa4ee2ca
scan_interval: 30
address: 113
slave: 1
offset: -15
scale: 0.5
climates:
- name: "water_heatpump_climate"
address: 113
slave: 1
input_type: holding
max_temp: 70
min_temp: 30
precision: 1
target_temp_register: 2
temp_step: 1
temperature_unit: C
hvac_onoff_register: 0
write_registers: true
offset: -15
scale: 0.5
Any idea?
tom_l
May 3, 2024, 1:18pm
7
Unfortunately no I don’t. I don’t actually use the modbus integration. Perhaps trying to read the same register is causing some sort of conflict?
As an alternative you could create a template sensor from the climate device if you need the current temperature attribute somewhere that does not support attributes directly.
tomvoo
(Tom)
May 3, 2024, 1:49pm
8
Thanks for the hint, using an entity attribute works fine! I didnt know those existed
1 Like