Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add channel for Eurotronic Spirit ZigBee Window Open Mode #781

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ public class ZigBeeBindingConstants {
public static final ChannelTypeUID CHANNEL_THERMOSTAT_COOLING_DEMAND = new ChannelTypeUID(
"zigbee:thermostat_coolingdemand");

public static final String CHANNEL_NAME_EUROTRONIC_SPZB001_WINDOW_OPEN = "spzb0001windowopen";
public static final String CHANNEL_LABEL_EUROTRONIC_SPZB001_WINDOW_OPEN = "Cooling Demand";
public static final ChannelTypeUID CHANNEL_EUROTRONIC_SPZB001_WINDOW_OPEN = new ChannelTypeUID(
"zigbee:eurotronic_spzb0001_window_open");

public static final String CHANNEL_NAME_DOORLOCK_STATE = "doorlockstate";
public static final String CHANNEL_LABEL_DOORLOCK_STATE = "Door Lock State";
public static final ChannelTypeUID CHANNEL_DOORLOCK_STATE = new ChannelTypeUID("zigbee:door_state");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/**
* Copyright (c) 2010-2022 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.zigbee.internal.converter;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ExecutionException;

import org.openhab.binding.zigbee.ZigBeeBindingConstants;
import org.openhab.binding.zigbee.converter.ZigBeeBaseChannelConverter;
import org.openhab.binding.zigbee.handler.ZigBeeThingHandler;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.core.types.Command;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.zsmartsystems.zigbee.CommandResult;
import com.zsmartsystems.zigbee.ZigBeeEndpoint;
import com.zsmartsystems.zigbee.zcl.ZclAttribute;
import com.zsmartsystems.zigbee.zcl.ZclAttributeListener;
import com.zsmartsystems.zigbee.zcl.clusters.ZclThermostatCluster;
import com.zsmartsystems.zigbee.zcl.protocol.ZclClusterType;
import com.zsmartsystems.zigbee.zcl.protocol.ZclDataType;

/**
* Converter for the thermostat system mode channel. The SystemMode attribute specifies the current operating mode of
* the thermostat,
*
* @author Robert Schmid - Initial Contribution
*
*/
public class ZigBeeConverterEurotronicSpzb0001WindowOpen extends ZigBeeBaseChannelConverter
implements ZclAttributeListener {
private Logger logger = LoggerFactory.getLogger(ZigBeeConverterEurotronicSpzb0001WindowOpen.class);

private final static int MANUFACTURER_EUROTRONIC = 0x1037;
private final static int ATTR_HOST_FLAGS = 0x4008;
private final static int WINDOW_OPEN_DISABLED = 16;
private final static int WINDOW_OPEN_ENABLED = 32;

private ZclThermostatCluster cluster;
private ZclAttribute attribute;

@Override
public Set<Integer> getImplementedClientClusters() {
return Collections.singleton(ZclThermostatCluster.CLUSTER_ID);
}

@Override
public Set<Integer> getImplementedServerClusters() {
return Collections.emptySet();
}

private ZclThermostatCluster getCluster(ZigBeeEndpoint endpoint) {
ZclThermostatCluster cluster = (ZclThermostatCluster) endpoint.getInputCluster(ZclThermostatCluster.CLUSTER_ID);
if (cluster == null) {
return null;
}

ZclAttribute hostFlagsAttribute = new ZclAttribute(cluster, ATTR_HOST_FLAGS, "Host Flags",
ZclDataType.UNSIGNED_24_BIT_INTEGER, false, true, true, true, MANUFACTURER_EUROTRONIC);
cluster.addAttributes(new HashSet<>(Arrays.asList(hostFlagsAttribute)));

return cluster;
}

@Override
public boolean initializeDevice() {
ZclThermostatCluster serverCluster = getCluster(endpoint);
if (serverCluster == null) {
logger.error("{}: Error opening device thermostat cluster", endpoint.getIeeeAddress());
return false;
}

try {
CommandResult bindResponse = bind(serverCluster).get();
if (bindResponse.isSuccess()) {
// Configure reporting
ZclAttribute attribute = serverCluster.getAttribute(ATTR_HOST_FLAGS);
CommandResult reportingResponse = attribute
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There still is one issue I wasn't yet able to resolve: Sometimes the following exception occurs when enabling the handler:

java.lang.IllegalArgumentException: You cannot append null data to a stream
	at com.zsmartsystems.zigbee.serialization.DefaultSerializer.appendZigBeeType(DefaultSerializer.java:43) ~[bundleFile:?]
	at com.zsmartsystems.zigbee.zcl.field.AttributeReportingConfigurationRecord.serialize(AttributeReportingConfigurationRecord.java:361) ~[bundleFile:?]
	at com.zsmartsystems.zigbee.zcl.ZclFieldSerializer.serialize(ZclFieldSerializer.java:38) ~[bundleFile:?]
	at com.zsmartsystems.zigbee.zcl.clusters.general.ConfigureReportingCommand.serialize(ConfigureReportingCommand.java:107) ~[bundleFile:?]
	at com.zsmartsystems.zigbee.ZigBeeNetworkManager.sendCommand(ZigBeeNetworkManager.java:903) ~[bundleFile:?]
	at com.zsmartsystems.zigbee.transaction.ZigBeeTransactionManager.send(ZigBeeTransactionManager.java:444) ~[bundleFile:?]
	at com.zsmartsystems.zigbee.transaction.ZigBeeTransactionManager.sendNextTransaction(ZigBeeTransactionManager.java:682) ~[bundleFile:?]
	at com.zsmartsystems.zigbee.transaction.ZigBeeTransactionManager.queueTransaction(ZigBeeTransactionManager.java:373) ~[bundleFile:?]
	at com.zsmartsystems.zigbee.transaction.ZigBeeTransactionManager.sendTransaction(ZigBeeTransactionManager.java:352) ~[bundleFile:?]
	at com.zsmartsystems.zigbee.ZigBeeNetworkManager.sendTransaction(ZigBeeNetworkManager.java:2030) ~[bundleFile:?]
	at com.zsmartsystems.zigbee.ZigBeeNode.sendTransaction(ZigBeeNode.java:963) ~[bundleFile:?]
	at com.zsmartsystems.zigbee.ZigBeeEndpoint.sendTransaction(ZigBeeEndpoint.java:596) ~[bundleFile:?]
	at com.zsmartsystems.zigbee.zcl.ZclCluster.sendCommand(ZclCluster.java:338) ~[bundleFile:?]
	at com.zsmartsystems.zigbee.zcl.ZclCluster.sendCommand(ZclCluster.java:349) ~[bundleFile:?]
	at com.zsmartsystems.zigbee.zcl.ZclCluster.setReporting(ZclCluster.java:1867) ~[bundleFile:?]
	at com.zsmartsystems.zigbee.zcl.ZclCluster.setReporting(ZclCluster.java:662) ~[bundleFile:?]
	at com.zsmartsystems.zigbee.zcl.ZclAttribute.setReporting(ZclAttribute.java:477) ~[bundleFile:?]
	at org.openhab.binding.zigbee.internal.converter.ZigBeeConverterEurotronicSpzb0001WindowOpen.initializeDevice(ZigBeeConverterEurotronicSpzb0001WindowOpen.java:96) ~[bundleFile:?]
	at org.openhab.binding.zigbee.handler.ZigBeeThingHandler.initializeDevice(ZigBeeThingHandler.java:514) ~[bundleFile:?]
	at org.openhab.binding.zigbee.handler.ZigBeeThingHandler.doNodeInitialisation(ZigBeeThingHandler.java:377) [bundleFile:?]
	at org.openhab.binding.zigbee.handler.ZigBeeThingHandler$1.call(ZigBeeThingHandler.java:227) [bundleFile:?]
	at org.openhab.binding.zigbee.handler.ZigBeeThingHandler$1.call(ZigBeeThingHandler.java:1) [bundleFile:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:829) [?:?]
19:44:59.119 [INFO ] [hab.event.ThingStatusInfoChangedEvent]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly this is considered an analog attribute, in which case there is another parameter that needs to go in the reporting configuration. If the attribute is analog, and you use the digital version of this method, then I think the library will try and send the extra parameter and it will be null.

.setReporting(REPORTING_PERIOD_DEFAULT_MIN, REPORTING_PERIOD_DEFAULT_MAX).get();
handleReportingResponse(reportingResponse, POLLING_PERIOD_DEFAULT, REPORTING_PERIOD_DEFAULT_MAX);
} else {
logger.debug("{}: Failed to bind thermostat cluster", endpoint.getIeeeAddress());
}
} catch (InterruptedException | ExecutionException e) {
logger.error("{}: Exception setting reporting ", endpoint.getIeeeAddress(), e);
}

return true;
}

@Override
public boolean initializeConverter(ZigBeeThingHandler thing) {
super.initializeConverter(thing);
cluster = getCluster(endpoint);
if (cluster == null) {
logger.error("{}: Error opening device thermostat cluster", endpoint.getIeeeAddress());
return false;
}

attribute = cluster.getAttribute(ATTR_HOST_FLAGS);
if (attribute == null) {
logger.error("{}: Error opening device thermostat Eurotronic host flags attribute", endpoint.getIeeeAddress());
return false;
}

// Add a listener, then request the status
cluster.addAttributeListener(this);
return true;
}

@Override
public void disposeConverter() {
cluster.removeAttributeListener(this);
}

@Override
public void handleCommand(final Command command) {
Integer value = null;
if (command instanceof OnOffType) {
// OnOff switches between OFF=WINDOW_OPEN_DISABLED and ON=WINDOW_OPEN_ENABLED
value = command == OnOffType.ON ? WINDOW_OPEN_ENABLED : WINDOW_OPEN_DISABLED;
}

if (value == null) {
logger.warn("{}: Host flags command {} [{}] was not processed", endpoint.getIeeeAddress(), command,
command.getClass().getSimpleName());
return;
}

monitorCommandResponse(command, attribute.writeValue(value));
}

@Override
public void handleRefresh() {
attribute.readValue(0);
}

@Override
public Channel getChannel(ThingUID thingUID, ZigBeeEndpoint endpoint) {
ZclThermostatCluster cluster = getCluster(endpoint);
if (cluster == null) {
logger.trace("{}: Thermostat cluster not found", endpoint.getIeeeAddress());
return null;
}

// Try to read the host flags attribute
ZclAttribute attribute = cluster.getAttribute(ATTR_HOST_FLAGS);
Object value = attribute.readValue(Long.MAX_VALUE);
if (value == null) {
logger.trace("{}: Thermostat host flags returned null", endpoint.getIeeeAddress());
return null;
}

return ChannelBuilder
.create(createChannelUID(thingUID, endpoint,
ZigBeeBindingConstants.CHANNEL_NAME_EUROTRONIC_SPZB001_WINDOW_OPEN),
ZigBeeBindingConstants.ITEM_TYPE_SWITCH)
.withType(ZigBeeBindingConstants.CHANNEL_EUROTRONIC_SPZB001_WINDOW_OPEN)
.withLabel(ZigBeeBindingConstants.CHANNEL_LABEL_EUROTRONIC_SPZB001_WINDOW_OPEN)
.withProperties(createProperties(endpoint)).build();
}

@Override
public void attributeUpdated(ZclAttribute attribute, Object val) {
logger.debug("{}: ZigBee attribute reports {}", endpoint.getIeeeAddress(), attribute);
if (attribute.getClusterType() == ZclClusterType.THERMOSTAT
&& attribute.isManufacturerSpecific()
&& attribute.getManufacturerCode() == MANUFACTURER_EUROTRONIC
&& attribute.getId() == ATTR_HOST_FLAGS) {
Integer value = (Integer) val;
if (value != null && (value & WINDOW_OPEN_DISABLED) != 0) {
updateChannelState(OnOffType.ON);
} else {
updateChannelState(OnOffType.OFF);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public ZigBeeDefaultChannelConverterProvider() {
channelMap.put(ZigBeeBindingConstants.CHANNEL_THERMOSTAT_COOLING_DEMAND,
ZigBeeConverterThermostatPiCoolingDemand.class);
channelMap.put(ZigBeeBindingConstants.CHANNEL_THERMOSTAT_SYSTEMMODE, ZigBeeConverterThermostatSystemMode.class);
channelMap.put(ZigBeeBindingConstants.CHANNEL_EUROTRONIC_SPZB001_WINDOW_OPEN,
ZigBeeConverterEurotronicSpzb0001WindowOpen.class);
channelMap.put(ZigBeeBindingConstants.CHANNEL_FANCONTROL, ZigBeeConverterFanControl.class);
channelMap.put(ZigBeeBindingConstants.CHANNEL_WINDOWCOVERING_LIFT, ZigBeeConverterWindowCoveringLift.class);
channelMap.put(ZigBeeBindingConstants.CHANNEL_INSTANTANEOUS_DEMAND,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,14 @@
<state pattern="%.0f %%" readOnly="true" />
</channel-type>

<!-- Eurotronic SPZB0001 Host Flags -->
<channel-type id="eurotronic_spzb0001_window_open">
<item-type>Switch</item-type>
<label>Window Open</label>
<description>Window Open Mode Enabled</description>
<category>HVAC</category>
</channel-type>

<!-- Warning device -->
<channel-type id="warning_device">
<item-type>String</item-type>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<thing:thing-descriptions bindingId="zigbee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">

<thing-type id="eurotronic_spzb0001" listed="false">
<label>Eurotronic Spirit Zigbee Thermostat</label>
<description>Radiator Thermostat</description>
<category>WallSwitch</category>

<channels>
<channel id="batteryLevel" typeId="system.battery-level">
<properties>
<property name="zigbee_endpoint">1</property>
</properties>
</channel>
<channel id="thermostat_occupiedheating" typeId="thermostat_occupiedheating">
<properties>
<property name="zigbee_endpoint">1</property>
</properties>
</channel>
<channel id="thermostat_occupiedcooling" typeId="thermostat_occupiedcooling">
<properties>
<property name="zigbee_endpoint">1</property>
</properties>
</channel>
<channel id="thermostat_unoccupiedheating" typeId="thermostat_unoccupiedheating">
<properties>
<property name="zigbee_endpoint">1</property>
</properties>
</channel>
<channel id="thermostat_heatingdemand" typeId="thermostat_heatingdemand">
<properties>
<property name="zigbee_endpoint">1</property>
</properties>
</channel>
<channel id="thermostat_systemmode" typeId="thermostat_systemmode">
<properties>
<property name="zigbee_endpoint">1</property>
</properties>
</channel>
<channel id="eurotronic_spzb0001_window_open" typeId="eurotronic_spzb0001_window_open">
<properties>
<property name="zigbee_endpoint">1</property>
</properties>
</channel>
</channels>
<config-description>
<parameter name="zigbee_macaddress" type="text" readOnly="true" required="true">
<label>MAC Address</label>
</parameter>
</config-description>
</thing-type>
</thing:thing-descriptions>
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ tuya_ts0041,modelId=TS0041
tuya_ts0042,modelId=TS0042
tuya_ts0043,modelId=TS0043
tuya_ts0044,modelId=TS0044
eurotronic_spzb0001,vendor=Eurotronic,modelId=SPZB0001