So in the diagramm i see no usable values
So i my idea is following : IF the Modbus Power Value ist lower than “0” then set this value permanent to “0” .
here is my actual Yaml Version which is not working
I tried to generate a second variable but this also not works.
Are you sure the sensor is not returning 0 at night and that the values are actually signed and not unsigned?
And in the template sensor you set the value to initial: {{ states(‘sensor.Pv_leistung_2’) | float 0 }}
What does the text “initial:” do there? The value should be just the number
And please format your yaml with the </> feature so it is displayed correctly so we can see indentation and not bullets
that was my first intention that the values not read out correctly vie modbus , i tried only to get a single Word via Modbus, changed the register high and Low Word… , because i only need a Variable up to 7000w , this didnt worked.
The Inverter sets , the value correct to “0” for some minutes at night, after that SMA sets by itself to this great Value over night. When he starts up the Value is shown correctly .
This displayed Code is only the result of trying to get it run , so please don´t see this as a nearly working version
We cannot help you if you keep on posting yaml like bullets. PLEASE select the yaml, click the little </> button in the menu bar and save again. You can edit both your original post the what you just posted
First I indent so things are easier to read. And in some cases this is also required to make it work
I use the format float(variable,0). It is safer than piping with | as many falls into traps with order of operands.
The if statement checks if the sensor Pv_Leistung is less than 0. We convert the sensor to float as they are always returned as strings. We set the default of the float function to -1 so when the sensor is undefined, you get same result as when it is the negative value you look for.
the else statement sets the sensor to its existing value which is hopefully more relevant to hold on to than setting it to 0. If it is undefined like when you start, it defaults to 0
Always put a unique_id which can be any string but it has to be unique and you should avoid spaces as I have seen occational bugs with that. The unique ID enables additional user interface features so you can alter the icon etc. Otherwise you get a warning message that it cannot be managed because of missing unique_id. All the mqtt and template integrations supports this now so it is worth adding then everywhere. It does not alter the way the item works. If you later change the unique ID you have to remove some ghost things so define it once and never alter them. That is why many use some random string generator to make them. I personally key a string based on the name.