Depends on the device. For Arduino devices, look at @ogiewon's Hubduino integration.
Depends on how you write your rules. But yes, in general this is possible.