Newer
Older
homeassistant_config / template / mikroovn.yaml
- sensor:
    - name: Mikroovn Plug Power Factor
      availability: "{{ states.switch['mikroovn_plug_switch'].attributes['voltage'] | float(0) > 0 }}"
      state: |
        {# Calculate power factor #}
        {% set v = states.switch['mikroovn_plug_switch'].attributes['voltage'] | default(0) | float(0)  %}
        {% set a = states.switch['mikroovn_plug_switch'].attributes['current'] | default(0) | float(0) %}
        {% set wp = states.switch['mikroovn_plug_switch'].attributes['current_consumption'] | default(0) | float(0) %}
        {% set ap = v * (a/1000.0) %}
        {% if ap > 0 %}
          {% set pf = wp / ap * 100 %}
          {{ pf | round(2) }}
        {% else %}
          {{ 0 }}
        {% endif %}
      unit_of_measurement: "%"
      device_class: power_factor
      state_class: measurement

    - name: Mikroovn Energi
      state: "{{ states.switch['mikroovn_plug_switch'].attributes['current_consumption'] | default(0) | float(0) }}"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement