######################################################################################################
### @Tesla Powerwall - https://www.vcloudinfo.com/2018/01/going-green-to-save-some-green-in-2018.html
# # @CCOSTAN
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
######################################################################################################

#-------------------------------------------
group:
  Power:
    entities:
      - sensor.powerwall_battery_capacity
      - sensor.powerwall_battery_now
      - sensor.grid_now
      - sensor.house_now
      - sensor.solar_now
      - camera.grafana_solar_graph
#-------------------------------------------

sensor:

  - platform: rest
    name: House now
    resource: https://192.168.10.90/api/meters/aggregates
    method: GET
    verify_ssl: false
    value_template: '{{ value_json.load.instant_power / 1000 }}'
    unit_of_measurement: kWh

  - platform: rest
    name: Grid now
    resource: https://192.168.10.90/api/meters/aggregates
    method: GET
    verify_ssl: false
    value_template: '{{ value_json.site.instant_power / 1000 }}'
    unit_of_measurement: kWh

  - platform: rest
    name: Solar now
    resource: https://192.168.10.90/api/meters/aggregates
    method: GET
    verify_ssl: false
    value_template: '{{ value_json.solar.instant_power / 1000 }}'
    unit_of_measurement: kWh

  - platform: rest
    name: PowerWall Battery now
    resource: https://192.168.10.90/api/meters/aggregates
    method: GET
    verify_ssl: false
    value_template: '{{ value_json.battery.instant_power / 1000 }}'
    unit_of_measurement: kWh

  - platform: rest
    name: PowerWall Battery Capacity
    resource: https://192.168.10.90/api/system_status/soe
    method: GET
    verify_ssl: false
    value_template: '{{ 13500 // (100 / value_json.percentage) }}'
    unit_of_measurement: W

#-------------------------------------------

#
# automation:
# Located in the Grafana package.  Tweets out Solar Production Daily!
