# Flexit ventilation

**Very briefly described:**

* Flexit Uni 3
* Flexit modbus adapter CI66
* Intel NUC running Home assistant and with an USB RS485 adapter
* Homeyscript interacting directly with the home assistant API

Here is the homeyscript interacting with the API:

{% code title="vent.js" %}

```javascript
let variables = await Homey.logic.getVariables()
let getVar = (name) => {
    let x = _.find(variables, (val, key) => {return (val.name === name) })
    if (typeof x === 'undefined') throw new Error("Could not find variable [" + name + "]")
    return x
}
// Variables: home,bright,timeperiod,presence-2etg
let home = getVar('home').value
let vent = getVar('vent').value

// home: boolean
// vent: boolean

let fanmode = "Low"
if (home) {
    if (vent) {
        fanmode = "High"
    } else {
        fanmode = "Medium"
    }
}

let body = {
    "entity_id": "climate.flexit",
    "fan_mode": fanmode
}
let bodyencoded = JSON.stringify(body)
let token = '-----removed------' // get a token from the home assistant user settings

let response = await fetch("https://home.solweb.no/api/services/climate/set_fan_mode",
{
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
      'Authorization': 'Bearer ' + token
    },
    method: "POST",
    body: bodyencoded
})
let json = await response.json()
// console.log("Reponse: ", json)

if (json.length <= 0) {
    throw new Error("Empty response....")
}

return true;

```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://homey.solweb.no/custom-integrations/flexit.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
