-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for Energy Management #10189
Signed-off-by: Andrea Conte <andrea@conte.com> Signed-off-by: Conte Andrea <andrea@conte.com>
- Loading branch information
Showing
12 changed files
with
229 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
...nwebnet/src/main/java/org/openhab/binding/openwebnet/handler/OpenWebNetEnergyHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/** | ||
* Copyright (c) 2010-2021 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.openwebnet.handler; | ||
|
||
import static org.openhab.binding.openwebnet.OpenWebNetBindingConstants.CHANNEL_POWER; | ||
|
||
import java.util.Set; | ||
|
||
import javax.measure.quantity.Power; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.openhab.binding.openwebnet.OpenWebNetBindingConstants; | ||
import org.openhab.core.library.types.QuantityType; | ||
import org.openhab.core.library.unit.Units; | ||
import org.openhab.core.thing.ChannelUID; | ||
import org.openhab.core.thing.Thing; | ||
import org.openhab.core.thing.ThingTypeUID; | ||
import org.openhab.core.types.Command; | ||
import org.openhab.core.types.UnDefType; | ||
import org.openwebnet4j.communication.OWNException; | ||
import org.openwebnet4j.message.BaseOpenMessage; | ||
import org.openwebnet4j.message.EnergyManagement; | ||
import org.openwebnet4j.message.FrameException; | ||
import org.openwebnet4j.message.Where; | ||
import org.openwebnet4j.message.WhereEnergyManagement; | ||
import org.openwebnet4j.message.Who; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* The {@link OpenWebNetEnergyHandler} is responsible for handling commands/messages for a Energy Management OpenWebNet | ||
* device. It extends the abstract {@link OpenWebNetThingHandler}. | ||
* | ||
* @author Massimo Valla - Initial contribution | ||
* @author Andrea Conte - Energy management | ||
*/ | ||
@NonNullByDefault | ||
public class OpenWebNetEnergyHandler extends OpenWebNetThingHandler { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(OpenWebNetEnergyHandler.class); | ||
|
||
public final static Set<ThingTypeUID> SUPPORTED_THING_TYPES = OpenWebNetBindingConstants.ENERGY_MANAGEMENT_SUPPORTED_THING_TYPES; | ||
|
||
public OpenWebNetEnergyHandler(Thing thing) { | ||
super(thing); | ||
} | ||
|
||
@Override | ||
protected Where buildBusWhere(String wStr) throws IllegalArgumentException { | ||
return new WhereEnergyManagement(wStr); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
logger.debug("initialize() thing={}", thing.getUID()); | ||
super.initialize(); | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
logger.debug("dispose() thing={}", thing.getUID()); | ||
super.dispose(); | ||
} | ||
|
||
@Override | ||
protected void requestChannelState(ChannelUID channel) { | ||
logger.debug("requestChannelState() thingUID={} channel={}", thing.getUID(), channel.getId()); | ||
try { | ||
bridgeHandler.gateway.send(EnergyManagement.requestActivePower(deviceWhere.value())); | ||
} catch (OWNException e) { | ||
logger.error("requestChannelState() OWNException thingUID={} channel={}: {}", thing.getUID(), | ||
channel.getId(), e.getMessage()); | ||
} | ||
} | ||
|
||
@Override | ||
protected void handleChannelCommand(ChannelUID channel, Command command) { | ||
logger.warn("handleChannelCommand() Read only channel, unsupported command {}", command); | ||
} | ||
|
||
@Override | ||
protected String ownIdPrefix() { | ||
return Who.ENERGY_MANAGEMENT.value().toString(); | ||
} | ||
|
||
@Override | ||
protected void handleMessage(BaseOpenMessage msg) { | ||
logger.debug("handleMessage({}) for thing: {}", msg, thing.getUID()); | ||
super.handleMessage(msg); | ||
|
||
if (msg.isCommand()) { | ||
logger.warn("handleMessage() Ignoring unsupported command for thing {}. Frame={}", getThing().getUID(), | ||
msg); | ||
return; | ||
} else { | ||
updateActivePower(msg); | ||
} | ||
} | ||
|
||
/** | ||
* Updates energy power state based on a EnergyManagement message received from the OWN network | ||
* | ||
* @param msg the EnergyManagement message received | ||
* @throws FrameException | ||
*/ | ||
// private void updateActivePower(EnergyManagement msg) { | ||
private void updateActivePower(BaseOpenMessage msg) { | ||
logger.debug("updateActivePower() for thing: {}", thing.getUID()); | ||
Integer activePower; | ||
try { | ||
activePower = Integer.parseInt(msg.getDimValues()[0]); | ||
updateState(CHANNEL_POWER, new QuantityType<Power>(activePower, Units.WATT)); | ||
} catch (FrameException e) { | ||
logger.warn("FrameException on frame {}: {}", msg, e.getMessage()); | ||
updateState(CHANNEL_POWER, UnDefType.UNDEF); | ||
} | ||
} | ||
} // class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
bundles/org.openhab.binding.openwebnet/src/main/resources/OH-INF/thing/BusEnergyMeter.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<thing:thing-descriptions bindingId="openwebnet" | ||
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 for BUS Energy Management Central Unit (BTicino F52x) --> | ||
<thing-type id="bus_energy_meter"> | ||
<supported-bridge-type-refs> | ||
<bridge-type-ref id="bus_gateway"/> | ||
</supported-bridge-type-refs> | ||
|
||
<label>Energy Meter</label> | ||
<description>A OpenWebNet BUS/SCS Energy Meter. BTicino models: F52x</description> | ||
|
||
<channels> | ||
<channel id="power" typeId="power"/> | ||
</channels> | ||
|
||
<properties> | ||
<property name="vendor">BTicino/Legrand</property> | ||
<property name="model">BTI-F52x</property> | ||
<property name="ownDeviceType">1830</property> | ||
</properties> | ||
|
||
<representation-property>ownId</representation-property> | ||
|
||
<config-description> | ||
<parameter name="where" type="text" required="true"> | ||
<label>OpenWebNet Device Address (where)</label> | ||
<description>Example: 5N with N=[1-255]</description> | ||
</parameter> | ||
</config-description> | ||
|
||
</thing-type> | ||
</thing:thing-descriptions> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.