Sum all values in an hour from a grouped time series

hello community
i am using the open source v8.5.3
currently i have a time series data from the following query
SELECT
$__timeGroup(datetime, ‘15m’,0) AS time,
IF(count(0) > 0, 1, 0) as value,
type as metric
FROM
table_sensors
WHERE uid = 491
group by $__timeGroup(datetime,‘15m’,0), type
order by 1 asc
and i get this graph(i wont show all metrics all the time)

now i want to group it again by 1 hour intervals. i have to first group into 15 minute intervals because of the way the data works.(every 15 minutes there should be a atleast 1 new row(hence the if). I basically want to find out how many times in an hour rows have been added(value between 0 and 4)

i tried using with and grouping again, or just select twice but neither worked and both just summed every value in a certain metric and gave it a date with 1970 as the year(assuming this is a start date of sorts)

Help would be appreciated
Thank you