You don’t really have to format it at all. If you create a measure of type sum then when you select device_id in your Look/Explore, the measure will be aggregated to the appropriate level. The timension time has to be a number of course for this to work.
measure: todo {
type: sum
sql: ${time} ;;
value_format:
}
I added value_format in case you want to format the measure in specific way.