I hope everything is going well.
First and foremost, taking into account that your devices send ‘1’ when the Grid is on and ‘0’ when the Grid is off. You can create two synthetic variables to calculate the number of devices in On and Off status, in this order of ideas, the operation for each variable should be set as follows:
You have to bear in mind that the “fill_missing” function is only available for IoT Entreprenour plans and above. This function will help you to compute an expression containing multiple variables with different timestamps, to extend your knowledge about the synthetic variables, please click the following hyperlink: SyntheticVariables.
All the best,