Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - Valve Positioning control #79

Open
fir3drag0n opened this issue Oct 7, 2024 · 7 comments
Open

Feature Request - Valve Positioning control #79

fir3drag0n opened this issue Oct 7, 2024 · 7 comments
Assignees
Labels

Comments

@fir3drag0n
Copy link

fir3drag0n commented Oct 7, 2024

I would like to suggest to implement a valve positioning control:


# Add Valve Position Input to the Frontend Configuration
input:
  input_valve_position:
    name: Valve Position
    description: >
      The valve position entity to control for the respective TRVs.
    selector:
      entity:
        filter:
          - domain: climate
        multiple: true  # Allow multiple valve position entities

# Example action to adjust the valve position based on temperature
action:
  - service: climate.set_valve_position
    target:
      entity_id: !input input_valve_position
    data:
      position: >
        {% set current_temp = states('sensor.current_temperature') | float %}
        {% set target_temp = states('input_number.target_temperature') | float %}
        {% if current_temp < target_temp %}
          {{ (state_attr('climate.your_trv_entity', 'position') + 10) | min(100) }}  # Increase valve position
        {% else %}
          {{ (state_attr('climate.your_trv_entity', 'position') - 10) | max(0) }}  # Decrease valve position
        {% endif %}

You could implement a check if the trv offers one or two entities to control it. If it offers a second entity, the logic is reversed. Another step would be to setup the adjustment steps, for example to setup the % steps (5%, 10%, 20%, and so forth).

Description:

Valve opening degree

Valve open position (percentage) control. If the opening degree is set to 100%, the valve is fully open when it is opened. If the opening degree is set to 0%, the valve is fully closed when it is opened, and the default value is 100%. Note: only version v1.1.4 or higher is supported.

Valve closing degree

Valve closed position (percentage) control. If the closing degree is set to 100%, the valve is fully closed when it is closed. If the closing degree is set to 0%, the valve is fully opened when it is closed, and the default value is 100%. Note: Only version v1.1.4 or higher is supported.

@panhans panhans self-assigned this Oct 29, 2024
@fir3drag0n
Copy link
Author

fir3drag0n commented Nov 2, 2024

Something like that

blueprint:
  name: Dynamic Valve Position Control
  description: Control the TRV valve position dynamically or statically based on temperature.
  domain: automation
  input:
    current_temperature:
      name: Current Temperature Sensor
      description: The sensor providing the current temperature.
      selector:
        entity:
          domain: sensor
    target_temperature:
      name: Target Temperature Entity
      description: The target temperature entity of the climate control.
      selector:
        entity:
          domain: climate
    kp_value:
      name: Proportional Gain (Kp) Slider
      description: Adjust the proportional gain to control valve responsiveness. Range: 1-100.
      selector:
        number:
          min: 1
          max: 100
          step: 1
    valve_step_size:
      name: Valve Step Size (%) Slider
      description: The percentage by which the valve position should be adjusted for static control.
      selector:
        number:
          min: 1
          max: 100
          step: 1
    dynamic_valve_control:
      name: Enable Dynamic Valve Control
      description: Enable or disable dynamic valve control.
      selector:
        boolean: {}
    valve_position:
      name: Valve Position Number
      description: The number representing the current valve position.
      selector:
        entity:
          domain: number

trigger:
  - platform: state
    entity_id: !input current_temperature
  - platform: state
    entity_id: !input.target_temperature
  - platform: state
    entity_id: !input.kp_value
  - platform: state
    entity_id: !input.valve_step_size
  - platform: state
    entity_id: !input.dynamic_valve_control

condition: []

action:
  - variables:
      current_temp: "{{ states[!input.current_temperature].state | float }}"
      target_temp: "{{ state_attr(!input.target_temperature, 'temperature') | float }}"
      current_valve_position: "{{ states[!input.valve_position].state | float }}"
  - choose:
      - conditions:
          - condition: state
            entity_id: !input.dynamic_valve_control
            state: "on"
        sequence:
          - variables:
              calculated_position: "{{ ((target_temp - current_temp) * !input.kp_value) | int }}"
          - service: input_number.set_value
            data:
              entity_id: !input.valve_position
              value: "{{ [calculated_position, 100] | min | max(0) }}"
      - conditions:
          - condition: state
            entity_id: !input.dynamic_valve_control
            state: "off"
        sequence:
          - variables:
              step_size: "{{ !input.valve_step_size }}"
              calculated_position: >
                {% if current_temp < target_temp %}
                  {{ current_valve_position + step_size }}
                {% else %}
                  {{ current_valve_position - step_size }}
                {% endif %}
          - service: input_number.set_value
            data:
              entity_id: !input.valve_position
              value: "{{ [calculated_position, 100] | min | max(0) }}"

@panhans
Copy link
Owner

panhans commented Nov 19, 2024

I will have a look into that soon. Also got some Sonoff TRVs now which support this.

@fir3drag0n
Copy link
Author

Please get in contact if you need testing support (in german possible as well)😊

@fir3drag0n
Copy link
Author

Is there any ETA or preview?

@panhans
Copy link
Owner

panhans commented Dec 20, 2024

Do you have any sources? This for example won't work. The max operator filters the maximum value of an array but with the min operator the minimum of that array is selected and the whole expression results in an error.

"{{ [calculated_position, 100] | min | max(0) }}"

Also my thermostats provide an entity for closed valve position and one for open valve position. So I think both have to be set in order to make the thermostat only fully close if it's set to off or the temperature is above the target temperature. But when it hits the target the valve should be open for a little bit in order to hold the current temperature.

//EDIT: I have a first idea.

@fir3drag0n
Copy link
Author

I just created with chatgpt 😂

@panhans
Copy link
Owner

panhans commented Dec 20, 2024

Ok, just wonder. This code doesn't work since 2022 anymore for home assistant. But check out the latest version and explore the new section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants