import requests
import json


def setHassSensor(value, token, url):
    """Set the value of the Homeassistant Sensor"""
    headers = {"Authorization": "Bearer {}".format(token), "Content-Type": "application/json"}
    data = {"state": value}
    response = requests.post(url, data=json.dumps(data), headers=headers)
    print(response)
    if response.status_code in [200, 201]:
        return True
    else:
        return False