Airstage plugin from Fujitsu

For heating/cooling related questions in Domoticz

Moderator: leecollings

Post Reply
Milifax
Posts: 69
Joined: Friday 23 June 2017 9:27
Target OS: Linux
Domoticz version: 2024.4
Location: The Netherlands
Contact:

Airstage plugin from Fujitsu

Post by Milifax »

Hi all,

recently got airconditioning installed from the brand Fujitsu. It comes with UTY-TFSXH3 WiFi units.
These can be controlled through Airstage app.

Does anybody know any plugin or way to control this airstage?
The Fujitsu plugin mentiond on the wiki is as far as I know for FGlair and not for Airstage controled devices.

Hope someone has the same issues and or is possible to control it already in Domoticz.
Milifax
Posts: 69
Joined: Friday 23 June 2017 9:27
Target OS: Linux
Domoticz version: 2024.4
Location: The Netherlands
Contact:

Re: Airstage plugin from Fujitsu

Post by Milifax »

Replying myself, did some digging around and gather info from the HomeAutomation-forum and together with the work of https://github.com/danielkaldheim/ha_airstage I made a python file myself. Very basic stuff, but perhaps someone could use it in the near future.

To start in from shell use 'python3 airco_check.py Airco_Slaapkamer' [or your own ini-file name]

The Airco_Slaapkamer.ini looks like this:

Code: Select all

[DEVICE]
# the IP address or hostname of the device
IP = 10.0.0.21

#The Device ID
ID = XXXXXXXXXXXX <- REPLACE THIS WITH YOU UNIT CODE, THESE ARE THE LAST 12 CHARACYERS OF YOUR WIFI UNITS SSID

# the idx of the switch in Domoticz to turn on or off
IDX_STATE = 789
IDX_SET = 790
IDX_OUTSIDE_TEMP = 800
IDX_INSIDE_TEMP = 799
The actual script airco_check.py looks like:

Code: Select all

#!/usr/bin/env python3

import requests
import json
import urllib.parse
import urllib

import time

import sys
import configparser

sleep = 300

DEVICE_NAME = sys.argv[1] if len(sys.argv) > 1 else 'example'
config = configparser.ConfigParser()
config.read(DEVICE_NAME + '.ini')

try:
    DEVICE = config['DEVICE']
except (KeyError, TypeError):
    raise Exception('Device file is unreadable or incomplete.')


DEVICE_URL = 'http://' + DEVICE['IP']
DEVICE_ID = DEVICE['ID']
IDX_STATE = DEVICE['IDX_STATE']
IDX_SET = DEVICE['IDX_SET']
IDX_OUTSIDE_TEMP = DEVICE['IDX_OUTSIDE_TEMP']
IDX_INSIDE_TEMP = DEVICE['IDX_INSIDE_TEMP']

DOMOTICZ_URL = 'http://10.0.0.50:8080/json.htm?'

while True:

    try:

        print('Monitoring the ' + DEVICE_NAME)

        #Check status of the device
        payload = ' { "device_id":"' + str(DEVICE_ID) + '" ,"device_sub_id":0,"req_id":"","modified_by":"","set_level":"03","list":["iu_onoff","iu_indoor_tmp","iu_outdoor_tmp"] } '
        headers = {}

        res = requests.post( DEVICE_URL + "/GetParam" , data=payload, headers=headers)

        data = res.json()
        state = data["value"] 
        #print(data["value"])
        #print(state["iu_indoor_tmp"])
        #print(state["iu_onoff"])


        #Update the temperatures read from unti towards Domoticz
        inside_temp = (int(state["iu_indoor_tmp"]) - 5000) / 100
        outside_temp = (int(state["iu_outdoor_tmp"]) - 5000) / 100
        
        #print(inside_temp) 
        #print(outside_temp)
        
        print('Sending Domoticz the current outside temp on the airco unit')
        getVars = {'type': 'command', 'param': 'udevice', 'idx': IDX_OUTSIDE_TEMP, 'nvalue': 0, 'svalue': outside_temp}
        webUrl = urllib.request.urlopen(DOMOTICZ_URL + urllib.parse.urlencode(getVars))

        print('Sending Domoticz the current inside temp of the airco room unit')
        getVars = {'type': 'command', 'param': 'udevice', 'idx': IDX_INSIDE_TEMP, 'nvalue': 0, 'svalue': inside_temp}
        webUrl = urllib.request.urlopen(DOMOTICZ_URL + urllib.parse.urlencode(getVars))



        #Check what Domoticz already knows about the state of the unit
        res = requests.post(DOMOTICZ_URL + 'type=command&param=getdevices&rid=' + IDX_STATE)
        data = res.json()
        #print('Now for the result of STATE')
        #print(data['result'][0]['Status'])

        STATE_DOMOTICZ = data['result'][0]['Status']

        if (state["iu_onoff"] == '0') and (STATE_DOMOTICZ == "On"):
            print('Telling Domoticz the device is OFF because it doesnt know yet')
            getVars = {'type': 'command', 'param': 'switchlight', 'idx': IDX_STATE, 'switchcmd': 'Off', 'level': 0, 'passcode': ''}
            webUrl = urllib.request.urlopen(DOMOTICZ_URL + urllib.parse.urlencode(getVars))
        if (state["iu_onoff"] == '1') and (STATE_DOMOTICZ =="Off"):   
            print('Telling Domoticz the device is ON because it doesnt know yet')
            getVars = {'type': 'command', 'param': 'switchlight', 'idx': IDX_STATE, 'switchcmd': 'On', 'level': 0, 'passcode': ''}
            webUrl = urllib.request.urlopen(DOMOTICZ_URL + urllib.parse.urlencode(getVars))

        #Check status of what we should do
        time.sleep(5)
        res = requests.post(DOMOTICZ_URL + 'type=command&param=getdevices&rid=' + IDX_SET)
        data = res.json()
        
        #print('Now for the result')
        #print(data['result'][0]['Status'])

        SWITCH_SET_DOMOTICZ = data['result'][0]['Status']

        #Set state of the device to off
        payload = ' { "device_id":"' + str(DEVICE_ID) + '" ,"device_sub_id":0,"req_id":"","modified_by":"","set_level":"02","value":{"iu_onoff":"0"}}'
        headers = {}
       
        if (state["iu_onoff"] == '1') and (SWITCH_SET_DOMOTICZ == 'Off') :          
            res = requests.post( DEVICE_URL + "/SetParam" , data=payload, headers=headers)
            #Tell Domoticz it is off now
            getVars = {'type': 'command', 'param': 'switchlight', 'idx': IDX_STATE, 'switchcmd': 'Off', 'level': 0, 'passcode': ''}
            webUrl = urllib.request.urlopen(DOMOTICZ_URL + urllib.parse.urlencode(getVars))


        #Let's check the time so we can switch off some lights
        #Get Servertime of Domoticz
        #print(data['ServerTime'])
        time_now = time.strptime(data['ServerTime'], "%Y-%m-%d %H:%M:%S")
        #print(time_now.tm_hour)

        #Check status of the device
        #payload = ' { "device_id":"' + str(DEVICE_ID) + '" ,"device_sub_id":0,"req_id":"","modified_by":"","set_level":"03","list":["iu_wifi_led"] } '
        #headers = {}

        #res = requests.post( DEVICE_URL + "/GetParam" , data=payload, headers=headers)

        #data = res.json()
        #print(data)
        #state = data["value"]
        #print('Wifi-LED State: ' + state["iu_wifi_led"])

        #Set state of the device to off
        #payload_off = ' { "device_id":"' + str(DEVICE_ID) + '" ,"device_sub_id":0,"req_id":"","modified_by":"","set_level":"02","value":{"iu_wifi_led":"0"}}'
        #payload_on = ' { "device_id":"' + str(DEVICE_ID) + '" ,"device_sub_id":0,"req_id":"","modified_by":"","set_level":"02","value":{"iu_wifi_led":"1"}}'
        #headers = {}



        #if ((time_now.tm_hour < 8) or (time_now.tm_hour > 19)) and (state["iu_wifi_led"] == '1') :
        #    print('Set the lights OFF')
        #    res = requests.post( DEVICE_URL + "/SetParam" , data=payload_off, headers=headers)
        #elif ((time_now.tm_hour > 8) or (time_now.tm_hour < 19)) and (state["iu_wifi_led"] == '0') :
        #    print('Set the lights ON')
        #    res = requests.post( DEVICE_URL + "/SetParam" , data=payload_on, headers=headers)

    except Exception as err:
        print(f"[ERROR]", {err})
                      
    time.sleep(sleep)
What the script does is checking the state of the indoor units of the airco. It communicaties the state towards Domoticz and checks in Domoticz the flag if it is ok to be on or not. If not it switches off. Control is done in Domoticz itself with DZvents. Also it communicates temps.
And a try to dynamically switch wifi led on and off but stopped with that and turned it off always from shell.

Wanted to share this for someone who might be looking for an answer to this as well. Maybe I will follow up on this with a more extended version, maybe not.
Do with it what you want, hope it helps some.

BR Milifax
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest