@softwaredevelopment/node-red-contrib-bodhi-device-occupancy-sensor
Version:
Occupancy Sensor device for bodhi node red
225 lines (201 loc) • 8.51 kB
HTML
<script type="text/javascript">
RED.nodes.registerType('Remote Occupancy Sensor', {
category: 'Bodhi',
color: '#B4C3CD',
labelColor: '#FFFFFF',
defaults: {
name: { value: '' },
connector: { value: '', type: 'Bodhi Connector' },
location: { value: "" },
logLevel: { value: 'debug' },
ignoreValidation: { value: false }
},
inputs: 1,
outputs: 1,
icon: 'device-icon.png',
label: function () {
return this.name || 'Remote Occupancy Sensor'
},
})
</script>
<script type="text/html" data-template-name="Remote Occupancy Sensor">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input required type="text" id="node-input-name" placeholder="Name of node">
</div>
<div class="form-row">
<label for="node-input-broker"><i class="fa-regular fa-building"></i> Location</label>
<input required type="text" id="node-input-location" placeholder="Location info">
</div>
<div class="form-row">
<label for="node-input-broker"><i class="fa fa-globe"></i> Connector</label>
<input required type="text" id="node-input-connector" placeholder="Bodhi Connector">
</div>
<hr />
<h3>Additional Settings</h3>
<div class="form-row" style="display: flex; align-items: center;">
<label for="node-input-ignoreValidation" style="flex: 0.35;">
<i class="fa fa-check-square"></i> Ignore Validation
</label>
<div class="toggle-button">
<input type="checkbox" id="node-input-ignoreValidation" style="display:none;">
<label id="ignoreValidationInsideLabel" for="node-input-ignoreValidation"></label>
</div>
</div>
<div class="form-row">
<label for="node-input-logLevel"><i class="fa fa-gear"></i> Log Level</label>
<select id="node-input-logLevel">
<option value="error">Error <i>(only errors in cli)</i></option>
<option value="warn">Warn <i>(warnings + errors in cli)</i></option>
<option value="info">Info <i>(warnings + errors + log/info in cli)</i></option>
<option value="debug" selected>Debug <i>(everything in cli)</i></option>
</select>
</div>
</script>
<script type="text/html" data-help-name="Remote Occupancy Sensor">
<h1>Node: Remote Occupancy Sensor</h1>
<p>The 'Remote Occupancy Sensor' node is a Bodhi node that represents a Remote Occupancy Sensor asset in bodhi. Follow these steps to use it:</p>
<h2>Configuration</h2>
<ol>
<li>Drag and drop the node from the Node-RED palette onto the workspace.</li>
<li>Configure the node by providing the following parameters:</li>
<ul>
<li><strong>Name</strong>: Provide a custom name for the node.</li>
<li><strong>Connector</strong>: Select the desired 'Bodhi Connector' configuration node from the drop-down list.</li>
<li><strong>Location</strong>: Specify the location information for the asset.</li>
</ul>
<li>Connect the node to other nodes in your flow to control the Remote Occupancy Sensor functionality.</li>
</ol>
<h2>Additional Settings Configurations</h2>
<p>These additional settings allow you an extra layer of node configuration.</p>
<ol>
<li><strong>Ignore Validation Toggle</strong>: Toggle this option if you want to send data to the server while ignoring validation. Without this, the node will not send invalid or unknown keys to the server.</li>
<li><strong>Log Level</strong>: Select what should be logged to your terminal while you are working with Node-RED flows.</li>
</ol>
<hr>
<h2>Usage</h2>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>payload
<span class="property-type">json</span>
</dt>
<dd>
This node does not required any inputs
</dd>
</dl>
<h3>Outputs</h3>
<dl class="message-properties">
<dt>payload
<span class="property-type">json</span>
</dt>
<dd>
A payload object which can be accessed using <code>msg.payload</code>.
This node will output this json object whenever the device get updated in bodhi which contains:
<dl class="message-properties">
<dt> message <span class="property-type">string</span></dt>
<dd><small>A message description about type of payload</small></dd>
</dl>
<dl class="message-properties">
<dt> asset_id <span class="property-type">string</span></dt>
<dd><small>Asset ID of device in bodhi</small></dd>
</dl>
<dl class="message-properties">
<dt>data
<span class="property-type">json</span>
</dt>
<dd>
<dl class="message-properties">
<dt>occFb<span class="property-type">boolean</span></dt>
<dd><small>Whether the room is occupied or not.</small></dd>
</dl>
<dl class="message-properties">
<dt>graceFb<span class="property-type">boolean</span></dt>
<dd><small>Grace or not.</small></dd>
</dl>
<hr>
<dl class="message-properties">
<dt> alarmFb <span class="property-type">boolean</span></dt>
<dd><small>Represents alarm status in bodhi asset.</small></dd>
</dl>
<dl class="message-properties">
<dt> alarmMessage <span class="property-type">string</span></dt>
<dd><small>Represents a message for alarm. It should be available if alarm is set to true</small></dd>
</dl>
<dl class="message-properties">
<dt> battLevelFb <span class="property-type">number</span></dt>
<dd><small>Represents the Battery level of device</small></dd>
</dl>
<dl class="message-properties">
<dt> lowBattFb <span class="property-type">boolean</span></dt>
<dd><small>Represents if device has low battery</small></dd>
</dl>
<dl class="message-properties">
<dt> energyUsageFb <span class="property-type">float</span></dt>
<dd><small>Represents how much energy is consumed by device in KWH</small></dd>
</dl>
<dl class="message-properties">
<dt> linkQualityFb <span class="property-type">string</span></dt>
<dd><small>Represents the link quality in bodhi asset</small></dd>
</dl>
<dl class="message-properties">
<dt> offlineFb <span class="property-type">boolean</span></dt>
<dd><small>Represents the offline/online status of device</small></dd>
</dl>
<dl class="message-properties">
<dt> activityTimeoutFb <span class="property-type">number</span></dt>
<dd><small>Represents the time in milliseconds, after which an alert is triggered if the device does not report.</small></dd>
</dl>
</dd>
</dl>
</dd>
</dl>
<h2>Example flow</h2>
<p>In this example, we'll create a flow to control a Bodhi Asset using this device node:</p>
<ol>
<li>Configure the 'Bodhi Connector' node to establish the Bodhi connection.</li>
<li>Add the device node to the flow.</li>
<li>Configure the node by providing a name, selecting the appropriate 'Bodhi Connector' from the drop-down list, and specifying the location.</li>
<li>Connect the node to suitable nodes that generate the desired input for controlling the device.</li>
<li>Continue building your flow by adding additional nodes for controlling or responding to its status.</li>
</ol>
</script>
<style>
.toggle-button {
display: inline-block;
position: relative;
width: 50px;
height: 26px;
}
.toggle-button input[type="checkbox"] {
display: none;
}
.toggle-button #ignoreValidationInsideLabel {
cursor: pointer;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
border-radius: 34px;
transition: background-color 0.4s;
width: auto;
}
.toggle-button #ignoreValidationInsideLabel:before {
content: "";
position: absolute;
width: 22px;
height: 22px;
border-radius: 50%;
background-color: #fff;
top: 2px;
left: 2px;
transition: transform 0.4s;
}
.toggle-button input:checked+#ignoreValidationInsideLabel {
background-color: #66bb6a;
}
.toggle-button input:checked+#ignoreValidationInsideLabel:before {
transform: translateX(24px);
}
</style>