Nested MySQL FROM query with two DBs
as described it will not work, but You can use prepared statements for this type of operations:

SET @tb_name = (SELECT grouptable.tablename FROM cmsdb.usertable LEFT JOIN cmsdb.grouptable ON cmsdb.grouptable.ID = cmsdb.usertable.groupID WHERE User = 2);


just keep in mind subquery above, must return single value, if not sure - add LIMIT 1

set @query = CONCAT('SELECT DATE(timestamp) As Date, AVG(Value) AS Value FROM ',  @tb_name , ' WHERE timestamp BETWEEN CURDATE()-INTERVAL 4 WEEK AND CURDATE() GROUP BY DATE(timestamp)');

prepare stmt1 from @query;
execute stmt1;

deallocate stmt1;