Skip to content

Commit

Permalink
* (Apollon77) Optimize IR - now works locally and via cloud in all cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollon77 committed Dec 5, 2022
1 parent 160bd3e commit bd52047
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,14 @@ The "ir-learn" state in this device is a Trigger which can be used to learn IR c

The "ir-send" state can be used to send a base64 encoded IR code to the device. This can be used to send the learned code from the "ir-learn" state.

**This way to control only works on the "main IR device" and for devices with Datapoints 201/202 only when connected locally (no cloud connection) (right now).**
**This way to control only works on the "main IR device".**

### The IR Sub Devices
The IR sub devices have a lot of "ir-*" states wich are all buttons to trigger the respective Button/IR code. The ir states should match the layout of the buttons in the mobile App.

Some devices have combi-states like "M0_T20_S3" (found by a Daikin Air conditioner) which means Mode 0, Temperature 20 and (Fan)-Speed 3. In fact you need to choose the right button. Until now we did not found a generic/automated way to find out which button is which.
The mobile App itself also tries to remember these settings, so as soon you trigger anything with the adapter (or the real ir controller of the device) the information from the App is outdated.

**This way to control only works when app cloud credentials are entered. The commands will be send also out via cloud for now for devices with datapoints 201/202.**

## Scenes features
When the app cloud credentials are entered and stored then the adapter also reads out the scenes from the app and creates them as objects in the adapter. The scenes can be triggered by setting the scene state to true.

Expand All @@ -143,6 +141,10 @@ When there are issues with the Tuya App Cloud synchronisation then additional lo
Send the log with reference to the generated GitHub issue to [email protected]

## Changelog

### __WORK IN PROGRESS__
* (Apollon77) Optimize IR - now works locally and via cloud in all cases

### 3.10.1 (2022-12-05)
* (Apollon77) Make info.ip writable to allow manual setting of IP address

Expand Down
15 changes: 7 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,8 @@ async function initDeviceObjects(deviceId, data, objs, values, preserveFields) {
delay: 300
};

await sendLocallyOrCloud(deviceId, physicalDeviceId, data.dpCodes['ir_send'].id, JSON.stringify(irData), true, true);
// To send the head/key format locally we need to send it to the physical device
await sendLocallyOrCloud(physicalDeviceId, physicalDeviceId, data.dpCodes['ir_send'].id, JSON.stringify(irData), undefined, true);
} else if (data.dpCodes['control'] && data.dpCodes['key_code'] && data.dpCodes['ir_code'] && data.dpCodes['type'] && data.dpCodes['delay_time']) {
const keyArr = keyData.compressPulse.split(':');
const dps = {};
Expand All @@ -603,7 +604,7 @@ async function initDeviceObjects(deviceId, data, objs, values, preserveFields) {
dps[data.dpCodes['type'].id.toString()] = 0;
dps[data.dpCodes['delay_time'].id.toString()] = 300;

await sendLocallyOrCloud(deviceId, physicalDeviceId, 'multiple', dps, undefined, true);
await sendLocallyOrCloud(physicalDeviceId, physicalDeviceId, 'multiple', dps, undefined, true);
}
};
const keyId = keyData.key.replace(adapter.FORBIDDEN_CHARS, '_').replace(/[ +]/g, '_');
Expand Down Expand Up @@ -781,23 +782,21 @@ async function initDeviceObjects(deviceId, data, objs, values, preserveFields) {
adapter.log.debug(`${deviceId} Send IR Code: ${value} with Type-Prefix 1`);
value = value.toString();
if (data.dpCodes['ir_send']) {
if (value.length % 4 === 0) {
value = '1' + value;
}
const irData = {
control: 'send_ir',
head: '',
'key1': value,
'key1': '1' + value,
type: 0,
delay: 300,
};
await sendLocallyOrCloud(deviceId, physicalDeviceId, data.dpCodes['ir_send'].id, JSON.stringify(irData), false, true);
await sendLocallyOrCloud(physicalDeviceId, physicalDeviceId, data.dpCodes['ir_send'].id, JSON.stringify(irData), undefined, true);
} else if (data.dpCodes['control'] && data.dpCodes['key_study']) {
const dps = {};
dps[data.dpCodes['control'].id.toString()] = 'study_key';
dps[data.dpCodes['key_study'].id.toString()] = value;
dps[data.dpCodes['type'].id.toString()] = 0;

await sendLocallyOrCloud(deviceId, physicalDeviceId, 'multiple', dps, undefined, true);
await sendLocallyOrCloud(physicalDeviceId, physicalDeviceId, 'multiple', dps, undefined, true);
}
});
}
Expand Down

0 comments on commit bd52047

Please sign in to comment.