Newer
Older
homeassistant_config / template / computer-plug.yaml
@root root on 8 Sep 2022 1 KB Added power factor for plugs
- sensor:
    - name: Computer Spænding
      state: '{{ (states.switch.computer_switch.attributes.voltage) | default(0)| float }}'
      unit_of_measurement: "V"
      device_class: voltage
    
    - name: Computer Strøm
      state: '{{ (states.switch.computer_switch.attributes.current) | default(0)| float * 0.001 }}'
      unit_of_measurement: "A"
      device_class: current
    
    - name: Computer Energi
      state: '{{ (states.switch.computer_switch.attributes.current_consumption) | default(0)| float }}'
      unit_of_measurement: "W"
      device_class: power
      
    - name: Computer Power Factor
      state: | 
        {# Calculate power factor #}
        {% set v = states.sensor.computer_spaending.state | float %}
        {% set a = states.sensor.computer_strom.state | float %}
        {% set wp = states.sensor.computer_energi.state | float %}
        {% set ap = v * a %}
        {% set pf = wp / ap * 100 %}
        
        {{ pf | round(2) }}
      unit_of_measurement: "%"
      device_class: power_factor