Automation based on value from sensor

Please have a read of this, particularly point 11.