Spanish businesses, restaurants and museums will not be allowed to set air-conditioners below 27 degrees Celsius in summer or heaters above 19C in winter under new energy-saving rules.
Shops will also have to keep doors closed and heating systems must be checked more often, Spanish Ecological Transition Minister Teresa Ribera said.
The emergency measures were announced following high summer temperatures and gas shortages due to the war in Ukraine, which have put strain on power systems across Europe.
Spain's new rules include switching off store window lights after 10pm.
Street lighting will not be affected. The measures remain only recommendations for private households, but people have been encouraged to turn off lights and lower blinds.
The government passed the bill as part of a bid to reduce the country's gas consumption by 7 per cent in line with the recent European Union energy agreements to limit dependency on Russian gas.
Last month the EU proposed a 15 per cent cut in gas use from August to March to its 27 member nations.
Russian energy giant Gazprom announced on July 25 that it would limit supplies to the rest of Europe through major gas pipeline Nord Stream 1 to 20 per cent capacity.
It was the latest development in a steadily worsening energy crisis across the continent since before the war began.
Ms Ribera said the measures would last until November 2023, when a decision will be made on whether to continue.
The Spanish government has already approved mass installation of solar panels on public building roofs and encouraged civil servants to work more from home.
Spanish Prime Minister Pedro Sanchez proposed last week that ministers, public officials and private sector employees stop wearing neckties during hot summer months.
A searing heatwave across Spain last month sparked major wildfires and fuelled blazes across 220 square kilometres of countryside.
ABC/Reuters/AP