# PFV plant energy helpers (kWh) for Home Assistant [#439]
#
# Paste into configuration.yaml. Riemann-sum integral: W -> kWh with the
# `integration` sensor platform (kept across restarts). Feeds the Energy
# dashboard (Settings > Dashboards > Energy > add grid/device consumption
# sources pointing at these kWh sensors).
#
# Node power comes from the ACPI power_meter read through the SNMP extend
# (see sensors-snmp-plant.yaml): sensor.pfv_tsys6_node_power /
# sensor.pfv_tsys7_node_power, in watts.

sensor:
  - platform: integration
    source: sensor.pfv_tsys6_node_power
    name: "PFV tsys6 node energy"
    unique_id: pfv_tsys6_node_energy
    unit_prefix: k
    round: 2
    method: left
    max_sub_interval:
      minutes: 5

  - platform: integration
    source: sensor.pfv_tsys7_node_power
    name: "PFV tsys7 node energy"
    unique_id: pfv_tsys7_node_energy
    unit_prefix: k
    round: 2
    method: left
    max_sub_interval:
      minutes: 5

# ---------------------------------------------------------------------------
# UPS load -> energy (APC on tsys1, Tripp Lite on tsys9):
# Preferred source is the NUT diagnostic sensor "Real power (W)" — enable it
# on the NUT device page (diagnostics are disabled by default). If your UPS
# does not expose real power, uncomment the template-watts fallback below and
# fill in the nominal wattage from the UPS nameplate.
#
#   - platform: integration
#     source: sensor.tsys1_ups_watts
#     name: "PFV tsys1 UPS energy"
#     unique_id: pfv_tsys1_ups_energy
#     unit_prefix: k
#     round: 2
#     method: left
#     max_sub_interval:
#       minutes: 5
#
# Fallback template (only if no realpower diagnostic entity exists):
#
# template:
#   - sensor:
#       - name: "PFV tsys1 UPS watts"
#         unique_id: pfv_tsys1_ups_watts
#         unit_of_measurement: "W"
#         device_class: power
#         state_class: measurement
#         state: >-
#           {{ (states('sensor.tsys1_ups_load') | float(0)
#               * NOMINAL_WATTS / 100) | round(0) }}
# ---------------------------------------------------------------------------
