Onewire DS2401

Hello
I have a onewire-system installed with several temperature and switch sensors. The temp-sensonrs work fine but the DS2401, which I put behind reed contacts to get the status of our windows either if they are open or not, I can not access. How can i get the status of each DS2401? I tried the examples like

Contact OneWireSensorA “Sensor A [%s]” {onewire=“deviceId=12.4AEC29CDBAAB;propertyName=sensed.A;invert;refreshinterval=15”}

but it did not work. Thanks for your help!

Cheers
Frieso

I have the same setup (DS2401 for reed contacts and DS18B20 for temperature), but reading both kinds of sensors the same way was not practical. Measuring the temperature for 16 sensors takes >10 seconds, whereas reed contacts should report their state much faster. So I bought a dedicated 1-wire controller where I use one bus for (slow) temperature measurement (every 10min) and one for fast reed contacts (every 10sec).

The temperature sensors are properly read by openhab, but I didn’t manage to read the reed contact state properly.

My approach: a script that runs as a daemon on my raspberry pi and checks the owfs uncached state every 10 seconds. It also caches the state, and if one of the contacts is added to or removed from the 1-wire bus, it uses curl to update corresponding switch items via the openhab REST API. If someone is interested, I could post the script here…

Hi paphko

where you able to read one single DS2401 state with openhab and if so how? I do not need a frequency of 10secs, 30-45 seconds would be sufficent.

Could you send the script you made and how you integrated it into openhab?
Thanks a lot

This script runs as a daemon on my Raspberry Pi. The mapping from 1-wire IDs to openhab switch items is done in a 1-wire alias file.

#!/bin/bash

OPENHAB_SERVER=http://openhab:8080/rest/items
OPENHAB_LOGIN=user:password
ONE_WIRE_ALIAS=/mnt/openhab/1wire.alias

# get all available 1wire ibuttons from alias file
# a line from that files looks like that: 01.055773160000=01_wohnzimmer
ALL_IBUTTONS=$(grep 01_ $ONE_WIRE_ALIAS | sed  's/01.\+=01_\(.\+\)/\1/g' | sort)
#echo "all ibuttons: $ALL_IBUTTONS"

# store state to check which ibuttons changed
STATE=""
# unfortunately, there are many false alarms where individual contacts are reported open although they are not.
# so we only report open contacts if they are reported twice in a row
STATE2=""

# loop to check for presence
FIRSTRUN=1
while true
do
# check whether openhab server is running, otherwise don't do anything
SINGLE_STATE=$(curl -u $OPENHAB_LOGIN -s $OPENHAB_SERVER/Reed_wohnzimmer/state)
if [ ! "$SINGLE_STATE" == "" ]
then
        # if state is uninitialized, clear cache and set all values again!
        if [ "$SINGLE_STATE" == "Uninitialized" ]
        then
                STATE=""
                STATE2=""
        fi

        # get all current reed contacts from uncached folder
        REED=$(owdir /uncached | grep 01_ | sed 's/\/uncached\/01_//g' | sort)
#               echo "all reeds: $REED"

        # check state changes
        if [ ! "$STATE" == "$REED" ] || [ ! "$STATE2" == "REED" ]
        then
                # iterate over all ibuttons and send updates
                for button in $ALL_IBUTTONS
                do
#                               echo "checking: $button..."

                        # the first run should always set the state
                        if [ $FIRSTRUN == 1 ]
                        then
                                # also set STATE to REED, which will be stored as STATE2, otherwise next iteration closed closed reeds again
                                STATE=$REED

                                # initialize CLOSED state
                                if [[ $REED =~ $button ]]
                                then
#                                               echo "$button initialized to CLOSED"
                                        curl -u $OPENHAB_LOGIN --header "Content-Type: text/plain" --request PUT --data "CLOSED" $OPENHAB_SERVER/Reed_$button/state

                                # initialize OPEN state
                                elif [[ ! $REED =~ $button ]]
                                then
#                                               echo "$button initialized to OPEN"
                                        curl -u $OPENHAB_LOGIN --header "Content-Type: text/plain" --request PUT --data "OPEN" $OPENHAB_SERVER/Reed_$button/state
                                fi

                        else

                                # if button is in reed but not in the last two states, it re-appeared
                                if [[ $REED =~ $button ]] && [[ ! $STATE =~ $button ]] && [[ ! $STATE2 =~ $button ]]
                                then
#                                               echo "$button changed to CLOSED"
                                        curl -u $OPENHAB_LOGIN --header "Content-Type: text/plain" --request PUT --data "CLOSED" $OPENHAB_SERVER/Reed_$button/state

                                # if botton is not in reed but in the second last states, it disappeared
                                elif [[ ! $REED =~ $button ]] && [[ ! $STATE =~ $button ]] && [[ $STATE2 =~ $button ]]
                                then
#                                               echo "$button changed to OPEN"
                                        curl -u $OPENHAB_LOGIN --header "Content-Type: text/plain" --request PUT --data "OPEN" $OPENHAB_SERVER/Reed_$button/state
                                fi
                        fi
                done

                # unset variable because first run is over
                FIRSTRUN=0

                # save as new state
                STATE2=$STATE
                STATE=$REED
        fi # state changed
fi #openhab is running

sleep 10 # run this loop every 10 seconds
done