# Leer estado dispositivo tuya en S7

**URL:** <https://discourse.nodered.org/t/leer-estado-dispositivo-tuya-en-s7/77541>\
**Category:** General\
**Created:** [13 April 2023 17:57 UTC](https://discourse.nodered.org/t/leer-estado-dispositivo-tuya-en-s7/77541 "2023-04-13T17:57:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmgimo75](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jmgimo75](https://discourse.nodered.org/u/jmgimo75)\
**Post date:** [13 April 2023 17:57 UTC](https://discourse.nodered.org/t/leer-estado-dispositivo-tuya-en-s7/77541/1 "2023-04-13T17:57:35Z")

</div>

Buenas.  
Soy nuevo es este mundo.  
Pido disculpas si me espreso mal  
Estoy intentando leer el estado de apertura de las persianas desde un dispositivo tuya, en un PLC S7.  
Quiero recibir el valor en enteros, pero sin éxito.  
Lo que se lee en la salida de la función es:  
{"data":{"dps":{"1":"stop","2":21},"t":1681406281},"deviceId":"xxxxxxxxxxxxxxxxxxx","deviceName":"Persiana 1"}

Lo que me gustaría leer seria el dps 2:"21" que es el valor de % apertura persiana.

MuchÍsimas gracias

---

<div class="post-metadata">

**Author:** ![KarolisL](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@KarolisL](https://discourse.nodered.org/u/KarolisL)\
**Post date:** [13 April 2023 19:27 UTC](https://discourse.nodered.org/t/leer-estado-dispositivo-tuya-en-s7/77541/3 "2023-04-13T19:27:17Z")

</div>

Hello, if it is possible please write in english.

Could you share a screenshot of DB that you are trying to read? Also paste a flow of your code?

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [13 April 2023 22:09 UTC](https://discourse.nodered.org/t/leer-estado-dispositivo-tuya-en-s7/77541/4 "2023-04-13T22:09:55Z")

</div>

> [@jmgimo75](#):
>
> Hello good.  
> I am new is this world.  
> I apologize if I express myself badly  
> I am trying to read the opening status of the blinds from a device of yours, in a PLC S7.  
> I want to receive the value in integers, but without success.  
> What is read in the output of the function is:  
> {"data":{"dps":{"1":"stop","2":21},"t":1681406281},"deviceId":"xxxxxxxxxxxxxxxxxxx","deviceName":"Shutter 1"}
> 
> What I would like to read would be the dps 2: "21" which is the value of blind opening %.
> 
> Thanks a lot

if we format a bit

```auto
msg.payload: {data: {dps: {1: 'stop', 
                           2: 21
                          },
                     t: 16814068281
                    },
              deviceid: "xxxxxxxxxxxxxxxxxxx",
              deviceName: "Persiana 1"
             }

```

So, hopefully, you need

```auto
let blindOpening = msg.payload.data.dps[2]

```

Edit  
For anyone else reading this, should have been

```auto
let blindOpening = msg.payload.data.dps['2']

```

thanks to @MecatronicaMADE

for pointing this out

---

<div class="post-metadata">

**Author:** ![jmgimo75](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jmgimo75](https://discourse.nodered.org/u/jmgimo75)\
**Post date:** [15 April 2023 16:34 UTC](https://discourse.nodered.org/t/leer-estado-dispositivo-tuya-en-s7/77541/5 "2023-04-15T16:34:05Z")

</div>

Good again.  
Sorry for not speaking in English.  
I am using a translator, in case something is not understood!!! XDD  
I'll give you some images  
1st is the flow that I have done

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/3/b3a9da82ec3d4a77cbf58c2e4707673b02c4ef80.png)

In it I have the following:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/c/6cac52a0db1cf75868548a1a8e0dbcb3c94a4d14.png)

And the result it gives me is:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/6/c6075d25c03374324043f3e8f3b571365b030cb1.png)  
When what I want is the result of the value "dps:2" which is the opening percentage of the blind.  
eg: reading 3 {25}

Thank you very much to all

---

<div class="post-metadata">

**Author:** ![MecatronicaMADE](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@MecatronicaMADE](https://discourse.nodered.org/u/MecatronicaMADE)\
**Post date:** [15 April 2023 17:24 UTC](https://discourse.nodered.org/t/leer-estado-dispositivo-tuya-en-s7/77541/6 "2023-04-15T17:24:10Z")

</div>

Hola @jmgimo75 y bienvenido a la comunidad, primero si que es cierto que si posteas en inglés tendrás mejor apoyo. Intente simular el entorno que tienes, y creo que con un nodo change podrías solucionarlo, te comparto el flujo para que lo importes en tu proyecto y lo modifiques a tu gusto.

```auto
[{"id":"028265c51778150b","type":"tab","label":"Flow 30","disabled":false,"info":"","env":[]},{"id":"860125e741c73f42","type":"inject","z":"028265c51778150b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":{\"dps\":{\"1\":\"stop\",\"2\":21},\"t\":1681406281},\"deviceId\":\"xxxxxxxxxxxxxxxxxxx\",\"deviceName\":\"Persiana 1\"}","payloadType":"json","x":730,"y":260,"wires":[["67be7cc9649f1701"]]},{"id":"67be7cc9649f1701","type":"change","z":"028265c51778150b","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.data.dps[\"2\"]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":880,"y":260,"wires":[["1781378dd4cfbb07"]]},{"id":"1781378dd4cfbb07","type":"debug","z":"028265c51778150b","name":"debug 45","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1040,"y":260,"wires":[]}]

```

Prácticamente lo que haras sera, almacenar en el payload el dato que te interesa, solamente:

> msg.payload = msg.payload.data.dps["2"]

![Screenshot from 2023-04-15 11-22-30](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/1/1163fa7ff774d2eaf650077ccabdf212790bec88.png)

Espero que pueda ayudar, saludos!
