How to get the avg like in the table calculated?

Hey all!
I have some data which are a number of 0 or 1 (switch on/off).
With the standard table below the plot I am able to plot avg. This value is exactly what I want, I can see that e.g. in the last 24h the switch was 0.2 percent of the time on.

Now I want to plot this percentage in a bar plot for the last 30d for every 1d.
If I am using the mean in the select, I will get different values. Don’t understand why…

Do you have a hint for me?

To describe my problem more in detail, here some pictures.
In the first one you see the value is 1 or 0 and the average for the last 2 days are 0.0281 like in the table.

And in the second picture you see that the mean of the last 2 days is with the group by command 0.0321 and not 0.0281.

What could I do?