#Making an estimated kWh sensor

1 messages · Page 1 of 1 (latest)

jaunty raptor
#

I have a w/sqm input and I wanted to convert that value to estimated solar production but I have no idea how.

#

something like ([sun w/sqm]*[average panel efficiency% NOCT])*[total panel area]

#

so 1000w sqm would equate to around 740w from the panel, 800w would be about 600w etc

wanton sonnet
#

You're looking for a PV simulator! I am working on one

jaunty raptor
wanton sonnet
#

That's what I'm making

jaunty raptor
#

of course that math assumes that the panels are pointing directly at the sun. Right now with the formula I'm estimating to make 340w but I'm actually making 160w

#

I'd have to add something like sin [sun elevation] to it

#

actually that's EXACTLY what I need to do

#

"(([sun w/sqm][average panel efficiency NOCT])[total panel area])sin [sun elevation]"

wanton sonnet
#

You can use a transposition model

#

It's making a projection from the sun vector to the in-plane radiation vector

jaunty raptor
#

and I'm making 153w right now

jaunty raptor
#

((445*11.7%)*6.65)sin 29.63

wanton sonnet
#

What type of radiation data do you have?

jaunty raptor
#

a weather station

wanton sonnet
#

I mean the type. GHI?

jaunty raptor
#

no idea

#

it's from ambient weather

wanton sonnet
#

It's important

#

Otherwise the calculation makes no sense

jaunty raptor
jaunty raptor
wanton sonnet
#

that's only a single number. It's not a linear formula, it always involves trigonometry

jaunty raptor
#

it's an estimated solar production value

#

It'll go on top of this

wanton sonnet
#

what's the area of your panel?

jaunty raptor
#

total? it's in the forrmula, 6.65sqm

#

it's actually a little less because of the spaces between the cells and where there's only glass/frame but it's good enough

#

I just don't know how to make it into a helper

wanton sonnet
#

it's gonna be a template sensor

jaunty raptor
#

and I have to limit the sun elevation because it'll go negative

#

normal or binary sensor?

wanton sonnet
#

why would it be binary

jaunty raptor
#

idk about helpers

#

I guess this moved from kwh to wanting watts so I can graph it

wanton sonnet
#

you do know what binary means? 0, 1?

#

anyway. If you lookup a basic transposition model (or ask AI to make one for you) you should be able to get a decently accurate power value

#

You dont need panel size or efficiency, you just need panel power at 1000W/m2 irradiance

jaunty raptor
jaunty raptor
jaunty raptor
#

idk how that would work though and I don't know how to write the forumula

wanton sonnet
#

No you don't need that

#

But feel free to ignore my advice

jaunty raptor
#

I'm close though. I need help on the sine part

wanton sonnet
#

Transposition model

jaunty raptor
wanton sonnet
#

that is the how

jaunty raptor
#

?

#

I have literaly no idea what you're talking about

wanton sonnet
#

have you googled what a transposition model is?

wanton sonnet
#

so basically you need this

#

you have G

#

you need to calculate θ

jaunty raptor
wanton sonnet
#

good moment to learn

#

you can use this as a starting point:

template:
  - sensor:
      - name: "Solar AOI"
        unit_of_measurement: "°"
        state: >
          {% set deg2rad = pi / 180 %}
          {% set rad2deg = 180 / pi %}

          {% set sun_azi = deg2rad * state_attr('sun.sun', 'azimuth') %}
          {% set sun_zen = deg2rad * (90 - state_attr('sun.sun', 'elevation')) %}
          
          {% set panel_tilt = deg2rad *  30.0 | float %} 
          {% set panel_azi = deg2rad * 180 | float %} {# 180 deg = south #}

          {% set cos_aoi =
            cos(sun_zen) * cos(panel_tilt) + sin(sun_zen) * sin(panel_tilt) * cos(sun_azi - panel_azi)
          %}

          {{ acos(cos_aoi) * rad2deg }}
jaunty raptor
wanton sonnet
wanton sonnet
jaunty raptor
#

ah

#

also a slightly separate question, how do I limit output to 0 for a helper?

wanton sonnet
#

you cant, only for templates

jaunty raptor
#

I'm basically trying to limit solar production values so it doesn't go above another value

#

so it shouldn't be negative

#

I wanted to either limit the value to 0 or limit the value to the max of another value

wanton sonnet
#

you would need a template for that

jaunty raptor
#

template helper?

wanton sonnet
#

max(max(input, reference), 0)

#

yes

jaunty raptor
#

template sensor or?

#

I'm not sure where I need to do it

wanton sonnet
#

template sensor or template helper both are okay

jaunty raptor
#

so how would I actually use it?

wanton sonnet
#

use what?

jaunty raptor
#

the max value

jaunty raptor
wanton sonnet
#

it's a template, it creates a sensor

wanton sonnet
#

read the documentation

jaunty raptor
#

am I even doing this right?

wanton sonnet
jaunty raptor
#

yeah I'm looking at it

#

what's sun.sun?

wanton sonnet
#

tracking the position of the sun

#

everyone has it

jaunty raptor
#

ah

#

the value is matching what I have already but my actual production is lower

wanton sonnet
#

well yeah that is basically doing the same thing as the formulas

#

but then you're dependent on a cloud integration

jaunty raptor
#

yeah

jaunty raptor
wanton sonnet
jaunty raptor
#

so it is under helpers

#

I just don't know which option it is

jaunty raptor
wanton sonnet
#

it's the right helper yeah

#

template is not right

jaunty raptor
wanton sonnet
#

I mean the code is not right

jaunty raptor
#

I just copy pasted yours

#

I tried the sun one but it just yelled at me

wanton sonnet
#

yeah this is all really basic stuff

#

ask the template people for help

jaunty raptor
#

basic for you maybe

#

I don't even know what result I'm supposed to be getting here

wanton sonnet
#

basically this measures the angle between the sun and your panel

#

so if the sun is directly on the panel it returns an angle of 0

jaunty raptor
#

shouldn't it only be a number?

wanton sonnet
#

if it is hitting it from the side the angle is 90 degrees

#

yes it's a number

#

idk why you typed yah

jaunty raptor
#

I was wondering wtf that was

#

wait why do I need the rest of that stuff

#

that's what I was looking for

wanton sonnet
#

you still have to set panel tilt and azimuth

jaunty raptor
#

yeah that's an easy fix

wanton sonnet
#

the rest of the stuff is if you configure a template sensor directly in configuration.yaml

#

so you can do that, or just put this template in a template sensor helper without all the extra stuff

#

just try and see what works

jaunty raptor
#

so I think I'd need cosine instead of sine for the calculation now

wanton sonnet
#

why

jaunty raptor
#

well my current watt caulation is based on the angle of the sun, so elevation at noon is 90° or thereabouts. With the new one it's 0

#

when it's set elevation 0 for one and 90 for the other. they're swapped

#

so now I have 3 separate values to look at.

#

1 based on sun angle
2 based on your thing
3 with no elevation considered (as if the panels are always facing the sun)

#

I'm seeing about 470w on the panels atm

#

what a mess. really annoying the HA calculates angles in radians and not degrees

#

I have to have a helper to convert rad to degree every time I need one

wanton sonnet
#

if you want to actually use mine you still need:

{% set deg2rad = pi / 180 %}

{% set sun_azi = deg2rad * state_attr('sun.sun', 'azimuth') %}
{% set sun_zen = deg2rad * (90 - state_attr('sun.sun', 'elevation')) %}
{# replace by G = states('sensor.irrads') | float #}
{% set G = 0.3 %}

{% set panel_tilt = deg2rad *  90.0 | float %} 
{% set panel_azi = deg2rad * 308.32 | float %} {# 180 deg = south #}
{% set panel_power = 300 | float %} {# watt #}

{% set cos_theta =
  cos(sun_zen) * cos(panel_tilt) + sin(sun_zen) * sin(panel_tilt) * cos(sun_azi - panel_azi)
%}

{{ G * panel_power * cos_theta }}
#

this is making the assumption that all irradiation is beam irradiance. Which in reality is always false unless you have clear skies

jaunty raptor
wanton sonnet
#

sure but it doesnt tell you what the diffuse component is

jaunty raptor
#

yeah

jaunty raptor
#

I'm reading 440w and it's giving me 175

#

and yes I edited it

#

deg2rad is a thing?

wanton sonnet
#

you didn't set G

jaunty raptor
#

what's G?

wanton sonnet
#

the irradiance you measure

jaunty raptor
#

oh so I literally have to cut out the 0.3% and replace it with the sensor?

wanton sonnet
#

thats what I put in the comment above that line yes

#

im not sure how else you could get power

jaunty raptor
#

why not type is as sensor.irradiance as a placeholder so I'm not so confused lol

wanton sonnet
#

why not read

jaunty raptor
#

I do not code

#

I take everything that's just given to me as is

#

I don't know what things do

#

I don't know why things are there

wanton sonnet
#

so you read greyed out replace by ... and you think that's code?

#

interesting

jaunty raptor
wanton sonnet
#

something is not symmetric!

jaunty raptor
wanton sonnet
#

yeah, its on the line you selected

jaunty raptor
#

I don't know

#

doesn't work with it, doesn't work without it

wanton sonnet
#

check carefully what you're missing

jaunty raptor
wanton sonnet
#

sad

jaunty raptor
#

idk what to tell you

#

I said before, if it's there it doesn't like it, if it's not there it doesn't like it

wanton sonnet
jaunty raptor
wanton sonnet
#

divide panel power by 1000

jaunty raptor
#

there, more clear

wanton sonnet
#

it depends on what unit your irradiance sensor is, I had no way of knowing

jaunty raptor
#

ah

#

it's in watts

#

is there a way to round that to the nearest watt?

wanton sonnet
#

| round(0)

jaunty raptor
wanton sonnet
#

probably wanna set device class : power

jaunty raptor
#

but yeah I probably should anyway

#

also this only updated every 4 minutes

wanton sonnet
#

it will update whenever one of the inputs updates

#

so for sun platform thats once every few minutes, but your irradiance sensor is probably faster

jaunty raptor
#

ah

#

you get the elevation and azimuth from sun.sun?

#

actually I was going to say why not use the sun integration but that updates every 4 minutes too

wanton sonnet
#

this is using sun integration

jaunty raptor
#

oh duh. I guess I never noticed the stepping before

#

it was obvious here but now that I blew it up I see it on the other graphs too

wanton sonnet
#

im a bit red-green color blind so that graph doesnt make any sense to me lol

#

pick colors that are further apart

jaunty raptor
#

woops

wanton sonnet
#

what do you mean by stepping?

jaunty raptor
#

stepping like stairs

#

or did I just get closer

#

oh wait no blue's further

wanton sonnet
jaunty raptor
#

now that's harder for me to see

#

it's dark blue on black

#

so that finally works as intended! and I got the 0w limiter working too

jaunty raptor
#

how can I convert the sun irradiance to rad without a helper? {{ ((((states("sensor.irradiance_local") | float) * 0.117) * 6.65) * (states("sensor.sun_elevation") | sin)) | round }}

wanton sonnet
#

what do you mean irradiance to rad?

jaunty raptor
#

degrees to radians

jaunty raptor
wanton sonnet
#

uhh

#

irradiance and radians are totally unrelated just to make sure

jaunty raptor