MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord

    ESP8266 + DHT22 + Thingspeak in magic mirror

    Requests
    3
    11
    5653
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Gelomidor
      Gelomidor last edited by

      Hello Guys.

      Recently i discovered the world of raspberry and Linux. I started with the magic mirror project and now want to extend the functionality. I want to do this with adding extra sensor to the magic mirror. To measure the temperature in different living rooms. I’ve done this with the following hardware:

      I’ve set up a ESP8266 with DHT22 sensor on-board in the living room.

      I’ve successfully configured this with thing speak but i cant seem to find any module or code that can help me out, to read the information from thing speak (api) and show it on the mirror right top side.

      I hope someone can help me out to make a module that can read multiple channels (temp + humidity in different rooms) from Thing speak and show it on the mirror.

      Yours, Fabian

      1 Reply Last reply Reply Quote 0
      • tosti007
        tosti007 Module Developer last edited by

        I gave it a really quick look and noticed that they have a REST API. There is already a module for that here. Hope that this is what you are looking for!

        If there is anything don't hesitate to contact me!
        ProfileSwitcher, TouchNotifications

        Gelomidor 1 Reply Last reply Reply Quote 0
        • Gelomidor
          Gelomidor @tosti007 last edited by Gelomidor

          @tosti007 Hi, thank you for the reply. I’ve saw that one and tried it but it just sas: MMM-Rest loading… I’ve tried all kinds of urls, but i’m afraid that im too un-experienced to get it to work. Is there any chance that you can guide me to set it up correctly?

          My appreciation would be big! 🙂

          tosti007 1 Reply Last reply Reply Quote 0
          • tosti007
            tosti007 Module Developer @Gelomidor last edited by

            @Gelomidor I will give it a read and let you know when I know more 🙂

            If there is anything don't hesitate to contact me!
            ProfileSwitcher, TouchNotifications

            1 Reply Last reply Reply Quote 0
            • tosti007
              tosti007 Module Developer last edited by tosti007

              Alright so I read it partially and as I understand it you have to do it in a few steps:
              First you have to create a channel and configure it (don’t forget to set it to public). Important: don’t set it to public as this is not secure! Use the api key you have from the channel instead! You can use the api key by adding &api_key=YOUR_KEY at the end of the url you would use when the channel is public!

              The REST module accepts only single values from the URL. So you cannot get the whole feed at once. What you will have to do instead is retrieve only one field as text. How to do that can be found here under Get Last Entry in a Field Feed and then Text.
              So having configured a channel, having the right URL for the field you want with the api key in it (you can test if it’s correct by going to the URL yourself and you should see only a single value) the last thing for you to do is configure the module.
              How to do that can be found it the module’s README.md. Don’t forget to configure output aswell, else you won’t see anything on screen. Hope this is what you are looking for, if it still doesn’t work or you have any other questions don’t hesitate to ask/let me know!

              If there is anything don't hesitate to contact me!
              ProfileSwitcher, TouchNotifications

              Gelomidor 2 Replies Last reply Reply Quote 0
              • Gelomidor
                Gelomidor @tosti007 last edited by Gelomidor

                @tosti007 Thank you so much for your help! I was so close. everything you describe i did except for making it public.:D The url gives the correct value. What i dont get it is why are there so many links and why dont all links have a description above it? Should i only use celsius and humidity? Could you also explain what mapping means?

                {
                    format: '%.1f',
                    url: 'https://www.dirk-melchers.de/echo.php?text=22.54',
                },
                {
                    format: '%d%%',
                    url: 'https://www.dirk-melchers.de/echo.php?text=59.1',
                },
                {
                    format: '%s',
                    mapping: 'temperature',
                    url: 'https://www.dirk-melchers.de/echo.php?text=2',
                },
                {
                    format: '%d',
                    url: 'https://www.dirk-melchers.de/echo.php?text=62.1',
                },
                {
                    format: 'Lights %s',
                    mapping: 'on_off',
                    url: 'https://www.dirk-melchers.de/echo.php?text=true',
                }
                
                

                The urls i replace with my urls: https://api.thingspeak.com/channels/12345/fields/12345/last.txt
                Like this one for the humidity.
                With configure output you mean: if i have multiple fields i have to change that number. In my case, just for beginning:

                [Livingroom','@1','@2'],

                Too bad im at work and cant configure my raspberry. But this feels like it should work. 🙂


                Note from admin: please use Markup when posting code.

                tosti007 1 Reply Last reply Reply Quote 0
                • Gelomidor
                  Gelomidor @tosti007 last edited by

                  @tosti007 I got it all working! thank you for pointing me in the right direction!! 😃

                  tosti007 1 Reply Last reply Reply Quote 0
                  • tosti007
                    tosti007 Module Developer @Gelomidor last edited by tosti007

                    Thank you so much for your help!

                    You’re welcome 😃

                    What i dont get it is why are there so many links and why dont all links have a description above it?

                    There are so many links because you have to retrieve every field by itself. They don’t have a description because just defining a field to retrieve doesn’t display it yet, this is done in the output section.

                    Should i only use celsius and humidity?

                    You can use anything you want.

                    Could you also explain what mapping means?

                    Using mapping is a way to translate one value into another. For example you retrieve the state of your lamps and it returns a boolean. Just displaying true or false doesn’t look so nice. on or off would be better and make more sense in a human way. So you could use a mapping to translate that. For the example above the mapping would be:

                    mappings: {
                        on_off: {
                            true: 'on',
                            false: 'off',
                        },
                    },
                    

                    The urls i replace with my urls: https://api.thingspeak.com/channels/xxxxx/fields/2/last.txt

                    Don’t forget to make an url for each field.

                    With configure output you mean: if i have multiple fields i have to change that number.

                    No, output configures the way you display your sections (after mapping and formatting) on your mirror.
                    So for example you have defined 3 urls in the sections value. The first url is the state of your lamps (with a mapping), the second is the humidity in your living room and the third the temperature in your living room. And you want to display it like:

                    Lamps on
                    Livingroom 21 degrees 52%
                    

                    Then your output would look like:

                    output: [
                        ['Lamps','@1'], // use number 1 here because you defined that first in sections
                        ['Livingroom','@3','@2'] // you defined temperature as third, but we want to display it first,?so we use @3 first and @2 second
                    ],
                    

                    Does this explain everything? 🙂

                    If there is anything don't hesitate to contact me!
                    ProfileSwitcher, TouchNotifications

                    1 Reply Last reply Reply Quote 0
                    • tosti007
                      tosti007 Module Developer @Gelomidor last edited by

                      @Gelomidor ah great! You’re welcome and enjoy it 😃

                      If there is anything don't hesitate to contact me!
                      ProfileSwitcher, TouchNotifications

                      1 Reply Last reply Reply Quote 0
                      • tosti007
                        tosti007 Module Developer last edited by tosti007

                        @Gelomidor I just realised I made a mistake! Setti your channel to public isn’t secure (anyone would be able to check the states of your lamps ect). Instead you should add the api key to the url by using the same url you would use when it’s public and adding &api_key=YOUR_KEY at the end of the url. Please do update this! (also remove the channel id in the url you usef above in post 6)

                        If there is anything don't hesitate to contact me!
                        ProfileSwitcher, TouchNotifications

                        schlachtkreuzer6 1 Reply Last reply Reply Quote 0
                        • 1
                        • 2
                        • 1 / 2
                        • First post
                          Last post
                        Enjoying MagicMirror? Please consider a donation!
                        MagicMirror created by Michael Teeuw.
                        Forum managed by Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
                        This forum is using NodeBB as its core | Contributors
                        Contact | Privacy Policy