DS18B20 Rule for broadcast a notification

Hello Guys

I have a Problem

How i can send a notification when the temperature under 5°C degrees falls and then send a notification over 7°C degrees

I tested with many rule settings and nothing works.

It’s a DS18B20 Sensor with binding: OneWireGPIO Binding
The sensor is in my garage and so can not fall under 5°C degrees (water freeze)

I think the problem comes from dezimal positions

How i can fix this?

This is my sample under rules:

configuration: {}
triggers:

  • id: “1”
    configuration:
    itemName: Temperature_Sensor_13_Temperature
    state: 5.000 °C
    type: core.ItemStateUpdateTrigger
    conditions:
    actions:
  • inputs: {}
    id: “2”
    configuration:
    message: ACHTUNG Garage Temperatur fällt unter 5 °C
    icon: temperature
    type: notification.SendExtendedBroadcastNotification

First, please post code in code fences.

```
code goes here
```

Second, you’ve configured your rule to only trigger when the Item is exactly 5.000 °C. If the Item is 5.0 °C, 5.1 °C or 4.9999999999 °C the rule is not going to trigger.

What you want is for the rule to run when it’s below 5 °C and presumably another rule to run when it’s over 7 °C. So you need a rule condition (but only if section). There you can add an Item State condition to allow the rule to run when it’s < 5 °C. The Item needs to be changed so it triggers on any Item change (don’t use state update or else you’ll get triggers even if the temperature hasn’t changed.

Obviously you’ll need to have another rule for 7 °C.

But now you’ll discover a problem. You’ll get an alert every time the Item changes to a value below 5 °C. You probably don’t want that. Instead you probably want just one alert when it goes below 5 °C and only one other alert when it goes above 7 °C. To do this you can’t use just simple UI rules.

You have two options.

  1. Profile: There is a “hysteresis” profile that can be used here. Create a Switch Item linked to what ever channel Temperature_Sensor_13_Temperature is linked to (I’d suggest using more meaningful names for Items while you are at it). On the Link apply the Hysteresis profile and set the minimum to 5 °C and max to 7 °C. The Item will change to ON when the temp falls below 5 °C and remain ON until the temp rises above 7 °C. The Item will change to OFF when the temp rises above 7 °C and remain OFF until the temp falls below 5 °C. You can then use this Switch Item to trigger your rules instead of the temperature sensor itself. You can also use the switch Item to see if you are in an alerting state in other rules.

  2. A consolidated rule. Here you’ll need to add a Script Action to process the Item states. You can use Blockly.

When the temperature falls below 5 °C, an alert is sent and a flag is set indicating the alert was sent. No more alerts will be sent while the temp remains below 5 °C. When the flag is set and the temperature rises above 7 °C, an alert is sent and the flag is set back to false.

The over 7 °C alert is only sent if the under 5 °C alert has already been sent. And each alert will only be sent once.

ok
i just added the part 2 and not running.
what is my problem?

Running on IDLE, when i cool down under 5°C, no notifications send to me or it changed over 7°C, no message comming.


Try not to post screen shots where a code tab is available. This is particularly important with a rule because a screen shot doesn’t show the full context (e.g. triggers).

Post the contents of the code tab with code fences.

```
code goes here
```

Be sure to watch the logs for errors or warnings.

Add logging to the rule to see that it’s executing and what parts of the rule are running.

my code is

if (cache.private.exists('lowAlertSent') === false) {
  cache.private.put('lowAlertSent', 'false');
}
if ((items.getItem('Temperature_Sensor_13_Temperature').quantityState.lessThan(Quantity('5 °C'))) && (cache.private.get('lowAlertSent')) == 'false') {
  actions.NotificationAction.sendBroadcastNotification('ACHTUNG Garage Temperatur fällt unter 5 °C', 'temperature_cold', 'warn');
  cache.private.put('lowAlertSent', 'true');
} else if ((items.getItem('Temperature_Sensor_13_Temperature').quantityState.greaterThan(Quantity('7 °C'))) && (cache.private.get('lowAlertSent')) == 'true') {
  actions.NotificationAction.sendBroadcastNotification('Garage Temperatur ist über 7 °C', 'temperature_warm', 'info');
  cache.private.put('lowAlertSent', 'false');
}

Thing code and created a item from this thing

UID: onewiregpio:sensor:ebbe24125a
label: Garage_Fühler
thingTypeUID: onewiregpio:sensor
configuration:
  gpio_bus_file: /sys/bus/w1/devices/28-adab571f64ff/w1_slave
  refresh_time: 15
  precision: 2
location: Garage

That’s part of it and it’s useful. But I want the YAML code for the full rule.

It will look something like this:

configuration: {}
triggers:
  - id: "1"
    configuration:
      itemName: AdGuard_Protection
      state: ON
      previousState: OFF
    type: core.ItemStateChangeTrigger
  - id: "2"
    configuration:
      itemName: AdGuard_Protection
      state: OFF
      previousState: ON
    type: core.ItemStateChangeTrigger
conditions: []
actions:
  - inputs: {}
    id: "3"
    label: Send Alert
    description: Uses the alerting library to send an alert level message
    configuration:
      type: application/javascript
      script: >
        var {alerting} = require('rlk_personal');

        var logger = log('AdGuard');

        alerting.sendAlert('AdGuard Protection is now ' + event.itemState.toString().toLocaleLowerCase() + '.', logger);
    type: script.ScriptAction

Notice how it shows the triggers, conditions and actions. For a rule using Blockly it will show the XML that defines the graphical blocks as well as the JS code the blocks “compile” into.

In short, it shows everything.

Most of the time “not running” means the rule trigger is wrong. But the rule trigger is :man_shrugging: You’ve not posted it.

okay i see my problem

I have add this blocky to script page.

I add the blocky to my rule and said, when item state updated then run script and it works.
This was my first blockly.

See my code.

Thanks for help me to coding this :slight_smile:

configuration: {}
triggers:
  - id: "1"
    configuration:
      itemName: Temperature_Sensor_13_Temperature
    type: core.ItemStateUpdateTrigger
conditions: []
actions:
  - inputs: {}
    id: "3"
    configuration:
      blockSource: <xml xmlns="https://developers.google.com/blockly/xml"><block
        type="controls_if" id="D}.#OgSN$kz)m70k}(iO" x="84" y="271"><value
        name="IF0"><block type="oh_check_undefined_value"
        id="Fj-N0PALxwia-kVwtxJK"><field name="cacheType">.private</field><value
        name="key"><shadow type="text" id="dUpgmOf;2Kmu)@yjHmEa"><field
        name="TEXT">key</field></shadow><block type="text"
        id="dUpgmOf;2Kmu)@yjHmEa"><field
        name="TEXT">lowAlertSent</field></block></value></block></value><statement
        name="DO0"><block type="oh_store_value" id="$#wQJKSdbm.py2%n~@It"><field
        name="cacheType">.private</field><value name="value"><shadow type="text"
        id="cU(b$i!EAnOF~fC;VChC"><field
        name="TEXT">value</field></shadow><block type="text"
        id="cU(b$i!EAnOF~fC;VChC"><field
        name="TEXT">false</field></block></value><value name="key"><shadow
        type="text" id="P!}VyZu%JXp]ir.9hTav"><field
        name="TEXT">key</field></shadow><block type="text"
        id="P!}VyZu%JXp]ir.9hTav"><field
        name="TEXT">lowAlertSent</field></block></value></block></statement><next><block
        type="controls_if" id="ZaZCE8vjZ.*2x:]tRY8j"><mutation
        elseif="1"></mutation><value name="IF0"><block type="logic_operation"
        id="Jo%JjUMGcJy5LH,#)QYl"><field name="OP">AND</field><value
        name="A"><block type="oh_quantity_compare"
        id="^/b]^lqLOg_P+!C2rfFu"><field name="operand">lessThan</field><value
        name="first"><shadow type="oh_quantity"
        id="j1R1eEbA#ZDhTzg:1jB6"></shadow><block type="oh_getitem_attribute"
        id=")RF6:}%Pc:$~79GZDmB`"><mutation
        attributeName="QuantityState"></mutation><field
        name="attributeName">QuantityState</field><value name="item"><shadow
        type="oh_getitem" id="}|X3m%T2a$C|yP?I=F1j"><value
        name="itemName"><shadow type="oh_item"
        id="Aeqbb_Us*IupJ,3Q~AD/"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow></value></shadow><block
        type="oh_getitem" id="i57qw7uY:`;e@mA!Fmr1"><value
        name="itemName"><shadow type="oh_item"
        id="#5%uGF5R16G;i.pIG6yA"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="#5%uGF5R16G;i.pIG6yA"><mutation
        itemName="Temperature_Sensor_13_Temperature"
        itemLabel="Garage_Fühler"></mutation><field
        name="itemName">Temperature_Sensor_13_Temperature</field></block></value></block></value></block></value><value
        name="second"><shadow type="oh_quantity"
        id="KCb#E;NU;TL[V*c=RbZ,"></shadow><block type="oh_quantity"
        id="!KQ9{Bd_pGd;hCR7J);!"><value name="quantity"><shadow type="text"
        id="(ObP6r_K;,h49v|W_tfH"><field name="TEXT">10 W</field></shadow><block
        type="text" id="(ObP6r_K;,h49v|W_tfH"><field name="TEXT">5
        °C</field></block></value></block></value></block></value><value
        name="B"><block type="logic_compare" id="gF6d;d93#x|]A#7Jy7)/"><field
        name="OP">EQ</field><value name="A"><block type="oh_get_value"
        id="`#H]5WKKOyXs9(=gPF?s"><field name="cacheType">.private</field><value
        name="key"><shadow type="text" id="GINFkrY?4S{W?Z0WXOx#"><field
        name="TEXT">key</field></shadow><block type="text"
        id="GINFkrY?4S{W?Z0WXOx#"><field
        name="TEXT">lowAlertSent</field></block></value></block></value><value
        name="B"><block type="text" id="{wz/qVqW1:?1J{nWa65Q"><field
        name="TEXT">false</field></block></value></block></value></block></value><statement
        name="DO0"><block type="oh_sendBroadcastNotification"
        id="8=FtF$Ickp9bT=gSFeC,"><field name="severity">warn</field><value
        name="message"><shadow type="text" id="(xo^FCZ)z%k7SwXz`N1?"><field
        name="TEXT">message</field></shadow><block type="text"
        id="(xo^FCZ)z%k7SwXz`N1?"><field name="TEXT">ACHTUNG Garage Temperatur
        fällt unter 5 °C</field></block></value><value name="icon"><shadow
        type="text" id=",F+Lg5,[1yLX`GWdsOv*"><field
        name="TEXT">temperature_cold</field></shadow><block type="text"
        id=",F+Lg5,[1yLX`GWdsOv*"><field
        name="TEXT">temperature_cold</field></block></value><next><block
        type="oh_store_value" id="VyBqK|osKA{bJreOH[2w"><field
        name="cacheType">.private</field><value name="value"><shadow type="text"
        id="_Jayi|:yH+@JBX_FP@c="><field
        name="TEXT">value</field></shadow><block type="text"
        id="_Jayi|:yH+@JBX_FP@c="><field
        name="TEXT">true</field></block></value><value name="key"><shadow
        type="text" id="XdtvOLPvYPQWZJXpQDTX"><field
        name="TEXT">key</field></shadow><block type="text"
        id="XdtvOLPvYPQWZJXpQDTX"><field
        name="TEXT">lowAlertSent</field></block></value></block></next></block></statement><value
        name="IF1"><block type="logic_operation"
        id="}8?7oHv{bprfp%u9]kt;"><field name="OP">AND</field><value
        name="A"><block type="oh_quantity_compare"
        id=";keyoWqIey#SER=5_oVK"><field
        name="operand">greaterThan</field><value name="first"><shadow
        type="oh_quantity" id="j1R1eEbA#ZDhTzg:1jB6"></shadow><block
        type="oh_getitem_attribute" id="I7JWM#a9|bgJr8m8f7It"><mutation
        attributeName="QuantityState"></mutation><field
        name="attributeName">QuantityState</field><value name="item"><shadow
        type="oh_getitem" id="}|X3m%T2a$C|yP?I=F1j"><value
        name="itemName"><shadow type="oh_item"
        id="Aeqbb_Us*IupJ,3Q~AD/"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow></value></shadow><block
        type="oh_getitem" id="0$Tn*3]=50=L|1r(L=@v"><value
        name="itemName"><shadow type="oh_item"
        id="Y56kZ]?AXLL^z:#M6`V9"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="Y56kZ]?AXLL^z:#M6`V9"><mutation
        itemName="Temperature_Sensor_13_Temperature"
        itemLabel="Garage_Fühler"></mutation><field
        name="itemName">Temperature_Sensor_13_Temperature</field></block></value></block></value></block></value><value
        name="second"><shadow type="oh_quantity"
        id="KCb#E;NU;TL[V*c=RbZ,"></shadow><block type="oh_quantity"
        id="+/YvwEL*nbUW*ZR[+pd4"><value name="quantity"><shadow type="text"
        id="`(qj1CX8bm$n,54m#]UY"><field name="TEXT">10 W</field></shadow><block
        type="text" id="`(qj1CX8bm$n,54m#]UY"><field name="TEXT">7
        °C</field></block></value></block></value></block></value><value
        name="B"><block type="logic_compare" id="|~,ginrm.0I1zZobpi~A"><field
        name="OP">EQ</field><value name="A"><block type="oh_get_value"
        id="9p7gV^dTVDrKs_JZq{j6"><field name="cacheType">.private</field><value
        name="key"><shadow type="text" id=":zzBWo5]a@KM-CRm#PN#"><field
        name="TEXT">key</field></shadow><block type="text"
        id=":zzBWo5]a@KM-CRm#PN#"><field
        name="TEXT">lowAlertSent</field></block></value></block></value><value
        name="B"><block type="text" id="y.M)uaBSBhG#kfUu.COg"><field
        name="TEXT">true</field></block></value></block></value></block></value><statement
        name="DO1"><block type="oh_sendBroadcastNotification"
        id="Nx6{JM=D(;`:*(P`N;L#"><field name="severity">info</field><value
        name="message"><shadow type="text" id="biaROc)8VYP.s2t/_*nc"><field
        name="TEXT">message</field></shadow><block type="text"
        id="biaROc)8VYP.s2t/_*nc"><field name="TEXT">Garage Temperatur ist über
        7 °C</field></block></value><value name="icon"><shadow type="text"
        id="/Iye=h+0e#jEBnz0b931"><field
        name="TEXT">temperature_cold</field></shadow><block type="text"
        id="/Iye=h+0e#jEBnz0b931"><field
        name="TEXT">temperature_warm</field></block></value><next><block
        type="oh_store_value" id="tLwb!T#o)%+M]C5,~/M9"><field
        name="cacheType">.private</field><value name="value"><shadow type="text"
        id="/E{*RsyE]]t/*G|yp2-2"><field
        name="TEXT">value</field></shadow><block type="text"
        id="/E{*RsyE]]t/*G|yp2-2"><field
        name="TEXT">false</field></block></value><value name="key"><shadow
        type="text" id="RYQE}?o_uY]NRDCu3*(0"><field
        name="TEXT">key</field></shadow><block type="text"
        id="RYQE}?o_uY]NRDCu3*(0"><field
        name="TEXT">lowAlertSent</field></block></value></block></next></block></statement></block></next></block></xml>
      type: application/javascript
      script: >
        if (cache.private.exists('lowAlertSent') === false) {
          cache.private.put('lowAlertSent', 'false');
        }

        if ((items.getItem('Temperature_Sensor_13_Temperature').quantityState.lessThan(Quantity('5 °C'))) && (cache.private.get('lowAlertSent')) == 'false') {
          actions.NotificationAction.sendBroadcastNotification('ACHTUNG Garage Temperatur fällt unter 5 °C', 'temperature_cold', 'warn');
          cache.private.put('lowAlertSent', 'true');
        } else if ((items.getItem('Temperature_Sensor_13_Temperature').quantityState.greaterThan(Quantity('7 °C'))) && (cache.private.get('lowAlertSent')) == 'true') {
          actions.NotificationAction.sendBroadcastNotification('Garage Temperatur ist über 7 °C', 'temperature_warm', 'info');
          cache.private.put('lowAlertSent', 'false');
        }
    type: script.ScriptAction

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.