'Set all the config values if they exist and get initial state.'

def __init__(self, hass, config):

    value_template = config.get(CONF_VALUE_TEMPLATE)
    if (value_template is not None):
        value_template.hass = hass
    self._hass = hass
    self._config = {CONF_NAME: config.get(CONF_NAME), CONF_HOST: config.get(CONF_HOST), CONF_PORT: config.get(CONF_PORT), CONF_TIMEOUT: config.get(CONF_TIMEOUT), CONF_PAYLOAD: config.get(CONF_PAYLOAD), CONF_UNIT_OF_MEASUREMENT: config.get(CONF_UNIT_OF_MEASUREMENT), CONF_VALUE_TEMPLATE: value_template, CONF_VALUE_ON: config.get(CONF_VALUE_ON), CONF_BUFFER_SIZE: config.get(CONF_BUFFER_SIZE)}
    self._state = None
    self.update()
