Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions drivers/esphome_climate/driver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ local function getEntityTempStep()
return ENTITY.visual_target_temperature_step or ENTITY.target_temperature_step or 0.5
end

--- Valid C4 setpoint resolutions per the thermostatV2 proxy docs.
local VALID_RESOLUTIONS_C = { 0.5, 1, 2, 5 }
local VALID_RESOLUTIONS_F = { 0.5, 1, 2, 5 }
--- Valid C4 temperature resolutions per the thermostatV2 proxy docs.
--- F floor is 0.2; C has no documented floor.
local VALID_RESOLUTIONS_C = { 0.1, 0.5, 1, 2, 5 }
local VALID_RESOLUTIONS_F = { 0.2, 0.5, 1, 2, 5 }

--- Snap a resolution value to the nearest valid C4 resolution.
--- @param value number The raw resolution value.
Expand All @@ -179,6 +180,13 @@ local function snapResolution(value, validValues)
return best
end

--- Convert a Celsius delta to a Fahrenheit delta.
--- @param value number Temperature delta in Celsius.
--- @return number Temperature delta in Fahrenheit.
local function celsiusDeltaToFahrenheit(value)
return value * 9 / 5
end

--- Clamp a Celsius temperature to the entity's min/max range.
--- @param celsius number Temperature in Celsius.
--- @return number clamped Clamped temperature in Celsius.
Expand Down Expand Up @@ -398,7 +406,7 @@ local function sendCapabilities(entity)
local step = entity.visual_target_temperature_step or entity.target_temperature_step
if step ~= nil then
local res_c = snapResolution(step, VALID_RESOLUTIONS_C)
local res_f = snapResolution(step * 9 / 5, VALID_RESOLUTIONS_F)
local res_f = snapResolution(celsiusDeltaToFahrenheit(step), VALID_RESOLUTIONS_F)
Comment thread
derek-miller marked this conversation as resolved.
SendToProxy(PROXY_BINDING, "DYNAMIC_CAPABILITIES_CHANGED", {
HEAT_SETPOINT_RESOLUTION_C = res_c,
HEAT_SETPOINT_RESOLUTION_F = res_f,
Expand All @@ -409,6 +417,14 @@ local function sendCapabilities(entity)
}, "NOTIFY")
end

local currentStep = entity.visual_current_temperature_step
if currentStep ~= nil then
SendToProxy(PROXY_BINDING, "DYNAMIC_CAPABILITIES_CHANGED", {
CURRENT_TEMPERATURE_RESOLUTION_C = snapResolution(currentStep, VALID_RESOLUTIONS_C),
CURRENT_TEMPERATURE_RESOLUTION_F = snapResolution(celsiusDeltaToFahrenheit(currentStep), VALID_RESOLUTIONS_F),
}, "NOTIFY")
end

CAPABILITIES_SENT = true

-- Water heater extras
Expand Down
8 changes: 4 additions & 4 deletions drivers/esphome_climate/driver.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@
<current_temperature_max_c>150</current_temperature_max_c>
<current_temperature_min_f>-58</current_temperature_min_f>
<current_temperature_max_f>302</current_temperature_max_f>
<current_temperature_resolution_c>0.1</current_temperature_resolution_c>
<current_temperature_resolution_f>0.1</current_temperature_resolution_f>
<current_temperature_resolution_c>0.5</current_temperature_resolution_c>
<current_temperature_resolution_f>1</current_temperature_resolution_f>
<setpoint_resolution_c>0.5</setpoint_resolution_c>
<setpoint_resolution_f>1</setpoint_resolution_f>
<setpoint_heat_min_c>0</setpoint_heat_min_c>
Expand All @@ -135,9 +135,9 @@
<has_extras>False</has_extras>
<has_vacation_mode>False</has_vacation_mode>
<has_remote_sensor>True</has_remote_sensor>
<fan_modes></fan_modes>
<fan_modes/>
<hvac_modes>Off,Heat,Cool,Auto</hvac_modes>
<hold_modes></hold_modes>
<hold_modes/>
</capabilities>
<proxies>
<proxy proxybindingid="5001" primary="True" name="ESPHome Climate">thermostatV2</proxy>
Expand Down
Loading