I’m trying to create a template sensor which shows me my remaining amps on my power input in my house. I know i’ve got a 25 main fuse, and homeassistant can already see how much amps are being used right now using my smart meter (p1). I’ve got a sensor which shows me the currently used amps, but how can I create a template sensor which shows me the amount of amps I still have availible? I’m going to use this to support an EVSE charger with the amount available, so that i can charge my car using the full amount available.
However, I am not sure why you chose to calculate it that way. Surplus amperage is simply maximum minus consumed. For rvoosterhaut’s application, the Template Sensor would be simply this:
I’ll assume you’re making a self-deprecating joke; no software engineering degree is needed to grok templating (but some exposure to a STEM curriculum certainly helps).
No malice intended at all. My last programming class was fortran 66. Much has changed since then and I just try my best and help where I can (There is no better learning experience than trying to teach). A degree (or training) is not required but it certainly helps. Engineers are not known for their linguistic skills and all programming is in a foreign language until you learn.
That didn’t prevent me to self-learn C / C++ / Java / Python / Whatever language of the day, though
Syntax is just a detail. Once you have the grasp on how 3rd generation programming languages work (the “functional” ones are another beast), only the keywords / block delimiters change, basically…
This value_template is working, thanks! Now i’m trying to create a negative value. So i’ve got a 25 amp fuse. When i’m using 10 amp, it should say -15 availble.
I thought it was a easy as switching the formula around, but that doesn’t seem to work
Floating-point value, aka “float”, is one of the elementary type in any programming languages (Fortran included ), alongside integers (“int”), and strings.
in HA, all states are inherently strings, upon which you cannot do math operations like minus.
The |float operation instructs HA to first convert the inherently string state to a float value, which then allow you to to the - 25 math operation.
If the sensor’s name is remaining amperage then the value should be positive, not negative. A negative value implies a deficit of a resource, not a surplus. The remaining capacity for your 25 ampere circuit is a positive value.
Simple example: your car’s fuel gauge indicates a positive amount (not negative).
Your template isn’t using the float filter correctly.
The state value of any entity is a string (which means it is text and not a number such as an integer or a floating-point value). The purpose of using the float filter is to convert the string to a floating-point value. Only then can you use it in a calculation.
If really want to show a negative value for remaining capacity, either of these works but the second form is preferable:
BTW, as per koying’s latest comment, it’s the custom of this community to mark the first post that identifies the problem and suggests how to correct it (not a subsequent post that duplicates it).