Is it ok to turn off water heater when no one is home or using the water?
I'd advise against turning off and on the water tank daily. For the physical tank and parts, a hot water heater turns on and off frequently during it's operation and won't suffer any damage from the switching, with the possible exception of the controls themselves. The bigger concern is large temperature swings by leaving it off for long periods of time and then reheating the water.
Turning off a hot water heater and allowing it to cool to 32 to 42 °C (90 to 108 °F) can allow pathogens to grow. See this question and answer for more details about ideal water heater temperature settings.
Turning a cold tank on, if your system has a one way "check valve" preventing back flow of water into the municipal system, can result in a large pressure increase. That dramatic swing can overload the capabilities of a small expansion tank if you have one, and cause valves to fail in your home. The failing valves will be seen as dripping fixtures, running toilets, or a leaking TPR valve on the water tank itself.
For a vacation home where the tank is turned off for several months, I wouldn't have these concerns. The tank is typically allowed to cool well between the lower limit for pathogens, and the water lines often have air in them from being drained or are being run to purge the stale water, which allows for the expansion as the water heater turns back on.